PowerTools PlusPak for Windows Forms 8.0J
DrawDay イベント
使用例 

オーナードローのGcCalendarのビジュアル日付領域が変わるときに発生します。
構文
イベント データ

イベント ハンドラが、このイベントに関連するデータを含む、DrawDayEventArgs 型の引数を受け取りました。次の DrawDayEventArgs プロパティには、このイベントの固有の情報が記載されます。

プロパティ解説
BackColor描画される日付領域の背景色を取得します。  
Bounds描画される日付領域の境界線を表す四角形を取得します。  
ClientBounds描画される日付領域のクライアント境界線を表す四角形を取得します。  
Day描画される日付領域の日を表すSystem.Int32値を取得します。  
DayType描画される日のタイプを取得します。  
ForeColor描画される日付領域の前景色を取得します。  
Graphics日付に描画するグラフィック表面を取得します。  
IsSelected描画される日付が現在選択されているかどうかを表す値を取得します。  
IsTrailingDay描画される日付が隣接日かどうかを表す値を取得します。  
Month描画される日付の月を表すSystem.Int32値を取得します。  
Notes描画される日のメモを示す IList 値を取得します。  
NotesBounds描画されるメモの境界を表す矩形を取得します。  
RokuyouBounds描画される六曜の境界を表す矩形を取得します。  
RokuyouText描画される六曜のテキストを示す文字列値を取得します。  
Text描画される日付のテキストを表すstring値を取得します。  
TextBounds描画される日付テキストの境界を表す矩形を取得します。  
Year描画される日付の年を表すSystem.Int32値を取得します。  
解説
このイベントはオーナードローのGcCalendarで使用されます。CalendarTypeCalendarType.MonthDayDrawModeOwnerDrawDayまたはCalendarDrawMode.OwnerDrawDayAndMonthに設定されている時のみ発生します。このイベントを使用してGcCalendarの日付領域の描画に必要なタスクを実装することができます。
使用例

次のサンプルコードは、GcCalendarコントロールにオーナードローの日付領域を描画する方法を示します。コードでは、DrawDayイベントを使用してGcCalendarの各日付領域へ描画を行います。サンプルコードは、イベントハンドラのパラメーターとして渡されたDrawDayEventArgsクラスのプロパティとメソッドを使用して日付部分を描画します。この例では、フォームにすでにgcCalendar1という名前のGcCalendarコントロールが追加されていることを前提とします。DrawDayイベントがサンプルコードで定義されたイベントハンドラに処理されている必要があります。また、gcCalendar1がCalendarType.MonthDay および OwnerDrawDay モードで初期化されることを条件とします。

private void gcCalendar1_DrawDay(object sender, GrapeCity.Win.Calendar.DrawDayEventArgs e)
{
    // Get the DateTime for current day view.
    DateTime drawingDay = new DateTime(e.Year, e.Month, e.Day);

    // Define the default color of the brush as black.
    Brush myBrush = Brushes.Black;

    // Draw the background of current day view.
    e.DrawBackground();

    // Determine wehter the current day view is sunday.
    bool isSunday = drawingDay.DayOfWeek == System.DayOfWeek.Sunday;

    // Determine the color of the brush to draw different kinds of day view.
    if (e.IsTrailingDay)
    {
        myBrush = Brushes.Gray;
    }
    else if (isSunday)
    {
        myBrush = Brushes.Red;
    }

    // Define the format of text being drawn.
    StringFormat format = new StringFormat();
    format.Alignment = StringAlignment.Far;
    format.LineAlignment = StringAlignment.Center;

    // Draw the current day view text based on the current Font and the custom brush settings.
    e.Graphics.DrawString(e.Text, gcCalendar1.Font, myBrush, e.Bounds, format);

    // Draw the today image and focus rectangle for today day view and focused day view.
    if (drawingDay == DateTime.Today || drawingDay == gcCalendar1.FocusDate.BaseDate)
    {
        e.DrawTodayImageAndFocusRectangle();
    }
}
Private Sub gcCalendar1_DrawDay(ByVal sender As Object, ByVal e As Global.GrapeCity.Win.Calendar.DrawDayEventArgs)
    ' Get the DateTime for current day view.
    Dim drawingDay As New DateTime(e.Year, e.Month, e.Day)

    ' Define the default color of the brush as black.
    Dim myBrush As Brush = Brushes.Black

    ' Draw the background of current day view.
    e.DrawBackground()

    ' Determine the color of the brush to draw different kinds of day view.
    If e.IsTrailingDay Then
        myBrush = Brushes.Gray
    ElseIf drawingDay.DayOfWeek = System.DayOfWeek.Sunday Then
        myBrush = Brushes.Red
    End If

    ' Define the format of text being drawn.
    Dim format As New StringFormat()
    format.Alignment = StringAlignment.Far
    format.LineAlignment = StringAlignment.Center

    ' Draw the current day view text based on the current Font and the custom brush settings.
    e.Graphics.DrawString(e.Text, gcCalendar1.Font, myBrush, e.Bounds, format)

    ' Draw the today image and focus rectangle for today day view and focused day view.
    If drawingDay = DateTime.Today OrElse drawingDay = gcCalendar1.FocusDate.BaseDate Then
        e.DrawTodayImageAndFocusRectangle()
    End If
End Sub
プラットフォーム

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

参照

GcCalendar クラス
GcCalendar メンバ
DrawDay イベント
OnDrawDay メソッド

Send Feedback