GrapeCity.Win.Calendar 名前空間 > DrawDayEventArgs クラス : Graphics プロパティ |
次のサンプルコードは、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