You can custom-draw items using the same technique we discussed earlier. Set the Calendar.CustomDraw property to the appropriate value, then handle the Calendar.Draw event and perform the custom drawing in the event handler. In this case set Calendar.CustomDraw to CalendarItem. Keep in mind that filling an item with new color will cause the item contents (such as text, icons, etc) to be lost. So you may need to custom draw these too. Here is a small example that works relatively well in SingleMonth view:
if (e.Element == CustomDrawElements.CalendarItem)
{
Rectangle left = new Rectangle(
e.Bounds.X, e.Bounds.Y, e.Bounds.Width / 2, e.Bounds.Height);
Rectangle right = new Rectangle(
e.Bounds.X + e.Bounds.Width / 2, e.Bounds.Y, e.Bounds.Width - e.Bounds.Width / 2, e.Bounds.Height);
e.Graphics.FillRectangle(Brushes.Orange, left);
e.Graphics.FillRectangle(Brushes.PaleGoldenrod, right);
Rectangle bounds = new Rectangle(
e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1);
using (Pen pen = new Pen(e.Style.BorderLeftColor, 0))
e.Graphics.DrawRectangle(pen, bounds);
using (Brush brush = new SolidBrush(e.Style.HeaderTextColor))
{
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
e.Graphics.DrawString(e.Text, e.Style.HeaderFont, brush, bounds, format);
format.Dispose();
}
}
Regarding the dependency lines, the only way (I can think of) to draw Gantt-like dependencies in WinForms is by using global custom drawing as described in my previous post.
Regards,
Meppy