PocketPlanner Programmer's Guide

Calendar.Draw Event

See Also

Raised to allow custom drawing of calendar UI elements.

Namespace: MindFusion.Scheduling.Compact
Assembly: PocketPlanner

 Syntax

C#

public CustomDraw Draw

Visual Basic

Public Draw As CustomDraw

 Event Data

Draw event handlers receive an argument of type CustomDrawArgs.

 Remarks

This event is raised if the CustomDraw property is set to a value different than None.

 Example

The following example demonstrates how to use the CustomDraw property in conjunction with the Draw event. The example assumes that calendar references a valid Calendar instance.

The example draws a red ellipse around specific dates in a SingleMonth view.

C#

calendar.CurrentView = CalendarView.SingleMonth;
calendar.CustomDraw = CustomDrawElements.CellHeader;
calendar.Draw += new CustomDraw(calendar_Draw);

// ...

private bool IsHoliday(DateTime date)
{
    if (date.Day == 31 && date.Month == 12)
        return true;
    if (date.Day == 24 && date.Month == 5)
        return true;

    return false;
}

// ...

private void calendar_Draw(object sender, CustomDrawArgs e)
{
    if (e.Element == CustomDrawElements.CellHeader)
    {
        if (IsHoliday(e.Date))
            e.Graphics.DrawEllipse(Pens.Red, e.Bounds);
    }
}

Visual Basic

calendar.CurrentView = CalendarView.SingleMonth
calendar.CustomDraw = CustomDrawElements.CellHeader
AddHandler calendar.Draw, AddressOf calendar_Draw

' ...

Private Function IsHoliday(ByVal ddate As DateTime) As Boolean

    If ddate.Day = 31 And ddate.Month = 12 Then
        Return True
    End If

    If ddate.Day = 24 And ddate.Month = 5 Then
        Return True
    End If

    Return False

End Function

' ...

Private Sub calendar_Draw(ByVal sender As Object, ByVal e As CustomDrawArgs)

    If e.Element = CustomDrawElements.CellHeader Then

        If IsHoliday(e.Date) Then
            e.Graphics.DrawEllipse(Pens.Red, e.Bounds)
        End If

    End If

End Sub

 See Also