public override void DrawAppointment(System.Drawing.Graphics g, System.Drawing.Rectangle rect, Appointment appointment, bool isSelected, System.Drawing.Rectangle gripRect)
{
if (appointment == null)
throw new ArgumentNullException("appointment");
if (g == null)
throw new ArgumentNullException("g");
/*
* Logic for drawing the appointment:
* 1) Do something messy with the colours
*
* 2) Determine background pattern
* 2.1) App is locked -> HatchBrush
* 2.2) Normal app -> Nothing
*
* 3) Draw the background of appointment
*
* 4) Draw the edges of appointment
* 4.1) If app is selected -> just draw the selection rectangle
* 4.2) If not -> draw the gripper, border (if required) and shadows
*/
if (rect.Width != 0 && rect.Height != 0)
{
using (StringFormat format = new StringFormat())
{
format.Alignment = StringAlignment.Near;
format.LineAlignment = StringAlignment.Near;
Color start = InterpolateColors(appointment.BarColor, Color.White, 0.4f);
Color end = InterpolateColors(appointment.BarColor, Color.FromArgb(191, 210, 234), 0.7f);
// if appointment is locked, draw different background pattern
if ((appointment.Locked))
{
// Draw back
using (Brush m_Brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.LargeConfetti, Color.Blue, appointment.BarColor))
g.FillRectangle(m_Brush, rect);
// little transparent
start = Color.FromArgb(230, start);
end = Color.FromArgb(180, end);
GraphicsPath path = new GraphicsPath();
path.AddRectangle(rect);
}
// Draw the background of the appointment
using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical))
g.FillRectangle(aGB, rect);
// If the appointment is selected, only need to draw the selection frame
if (isSelected)
{
Rectangle m_BorderRectangle = rect;
using (Pen m_Pen = new Pen(appointment.BorderColor, 3))
g.DrawRectangle(m_Pen, rect);
m_BorderRectangle.Inflate(2, 2);
using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
g.DrawRectangle(m_Pen, m_BorderRectangle);
m_BorderRectangle.Inflate(-4, -4);
using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
g.DrawRectangle(m_Pen, m_BorderRectangle);
}
else
{
// Draw gripper
gripRect.Width += 1;
start = InterpolateColors(appointment.BorderColor, appointment.BarColor, 0.2f);
end = InterpolateColors(appointment.BorderColor, Color.White, 0.6f);
using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical))
g.FillRectangle(aGB, gripRect);
// Draw border if needed
if (appointment.DrawBorder)
using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
g.DrawRectangle(m_Pen, rect);
// Draw shadow lines
int xLeft = rect.X + 6;
int xRight = rect.Right + 1;
int yTop = rect.Y + 1;
int yButton = rect.Bottom + 1;
for (int i = 0; i < 5; i++)
{
using (Pen shadow_Pen = new Pen(Color.FromArgb(70 - 12 * i, Color.Black)))
{
g.DrawLine(shadow_Pen, xLeft + i, yButton + i, xRight + i - 1, yButton + i); //horisontal lines
g.DrawLine(shadow_Pen, xRight + i, yTop + i, xRight + i, yButton + i); //vertical
}
}
}
// draw appointment text
rect.X += gripRect.Width;
// width of shadow is 6.
rect.Width -= 6;
g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
g.DrawString(appointment.Title, this.BaseFont, SystemBrushes.WindowText, rect, format);
g.TextRenderingHint = TextRenderingHint.SystemDefault;
}
}
}