カレンダーの祝日と休日を設定するには、GcCalendarGrid.Holidaysプロパティに祝日または休日の日付と説明を追加します。日本の祝日と休日を設定する方法は、「国民の祝日と休日」で説明します。
GcCalendarGrid1.Holidays.Add(New DateTime(2013, 1, 1), "元日")
gcCalendarGrid1.Holidays.Add(new DateTime(2013, 1, 1), "元日");
GcCalendarGrid1.Holidays.Add(New DateTime(2014, 1, 1), "元日") GcCalendarGrid1(New DateTime(2014, 1, 1))(2, 0).CellStyleName = "defaultDayStyle" GcCalendarGrid1(New DateTime(2014, 1, 1))(2, 0).DateFormatType = GrapeCity.Win.CalendarGrid.CalendarDateFormatType.CalendarGrid GcCalendarGrid1(New DateTime(2014, 1, 1))(2, 0).DateFormat = "{HolidayName}" GcCalendarGrid1.ScrollIntoView(New DateTime(2014, 1, 1))
gcCalendarGrid1.Holidays.Add(new DateTime(2014, 1, 1), "元日"); gcCalendarGrid1[new DateTime(2014, 1, 1)][2, 0].CellStyleName = "defaultDayStyle"; gcCalendarGrid1[new DateTime(2014, 1, 1)][2, 0].DateFormatType = GrapeCity.Win.CalendarGrid.CalendarDateFormatType.CalendarGrid; gcCalendarGrid1[new DateTime(2014, 1, 1)][2, 0].DateFormat = "{HolidayName}"; gcCalendarGrid1.ScrollIntoView(new DateTime(2014, 1, 1));
Imports GrapeCity.Win.CalendarGrid GcCalendarGrid1.Holidays.AddRange(New CalendarHoliday() { New CalendarHoliday(New DateTime(2013, 1, 1), "元日"), New CalendarHoliday(New DateTime(2014, 1, 1), "元日"), New CalendarHoliday(New DateTime(2015, 1, 1), "元日"), New CalendarHoliday(New DateTime(2016, 1, 1), "元日"), New CalendarHoliday(New DateTime(2017, 1, 1), "元日"), New CalendarHoliday(New DateTime(2018, 1, 1), "元日") })
using GrapeCity.Win.CalendarGrid; gcCalendarGrid1.Holidays.AddRange(new CalendarHoliday[] { new CalendarHoliday(new DateTime(2013, 1, 1), "元日"), new CalendarHoliday(new DateTime(2014, 1, 1), "元日"), new CalendarHoliday(new DateTime(2015, 1, 1), "元日"), new CalendarHoliday(new DateTime(2016, 1, 1), "元日"), new CalendarHoliday(new DateTime(2017, 1, 1), "元日"), new CalendarHoliday(new DateTime(2018, 1, 1), "元日") });
注意 山の日は、国民の祝日の1つで、2016年から施行されます。 |
For i = 2016 To 2099 GcCalendarGrid1.Holidays.Add(New DateTime(i, 8, 11), "山の日") Next
for (int i = 2016; i < 2099; i++) { gcCalendarGrid1.Holidays.Add(new DateTime(i, 8, 11), "山の日"); }
Dim theDay As DateTime = New DateTime(2013, 1, 1) If GcCalendarGrid1.Holidays.Contains(theDay) Then Console.WriteLine("含まれます") Else Console.WriteLine("含まれません") End If
DateTime theDay = new DateTime(2013, 1, 1); if (gcCalendarGrid1.Holidays.Contains(theDay)) { Console.WriteLine("含まれます"); } else { Console.WriteLine("含まれません"); }
Imports GrapeCity.Win.CalendarGrid ' 既定のスタイルを削除する gcCalendarGrid1.Styles.Clear() Dim holidayStyle As New CalendarCellStyle() holidayStyle.BackColor = Color.Azure holidayStyle.ForeColor = Color.Blue Dim conditionalCelLStyle1 As New CalendarConditionalCellStyle("defaultDayStyle") conditionalCelLStyle1.Items.Add(new CalendarConditionalCellStyleItem(holidayStyle, ConditionalStyleOperator.IsHoliday)) GcCalendarGrid1.Styles.Add(conditionalCelLStyle1) GcCalendarGrid1.Holidays.Add(New DateTime(2014, 1, 1), "元日") ' セルにスタイル名と休日の日付書式を設定する GcCalendarGrid1(New DateTime(2014, 1, 1))(2, 0).CellStyleName = "defaultDayStyle" GcCalendarGrid1(New DateTime(2014, 1, 1))(2, 0).DateFormat = "{HolidayName}" GcCalendarGrid1.ScrollIntoView(New DateTime(2014, 1, 1))
using GrapeCity.Win.CalendarGrid; // 既定のスタイルを削除するgcCalendarGrid1.Styles.Clear(); var holidayStyle = new CalendarCellStyle(); holidayStyle.BackColor = Color.Azure; holidayStyle.ForeColor = Color.Blue; var conditionalCelLStyle1 = new CalendarConditionalCellStyle("defaultDayStyle"); conditionalCelLStyle1.Items.Add(new CalendarConditionalCellStyleItem(holidayStyle, ConditionalStyleOperator.IsHoliday)); gcCalendarGrid1.Styles.Add(conditionalCelLStyle1); gcCalendarGrid1.Holidays.Add(new DateTime(2014, 1, 1), "元日"); // セルにスタイル名と休日の日付書式を設定する gcCalendarGrid1[new DateTime(2014, 1, 1)][2, 0].CellStyleName = "defaultDayStyle"; gcCalendarGrid1[new DateTime(2014, 1, 1)][2, 0].DateFormat = "{HolidayName}"; gcCalendarGrid1.ScrollIntoView(new DateTime(2014, 1, 1));
Imports GrapeCity.Win.CalendarGrid Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' 既定のスタイルを削除する GcCalendarGrid1.Styles.Clear() ' 既定のスタイルによる休日 GcCalendarGrid1.Holidays.Add(New DateTime(2014, 1, 1), "元日") GcCalendarGrid1.Holidays.Add(New DateTime(2014, 1, 2), "年始休業") GcCalendarGrid1.Content(New DateTime(2014, 1, 2)).Tag = "私的な休日" Dim dynamicCellStyle As CalendarDynamicCellStyle = New CalendarDynamicCellStyle(AddressOf condition) dynamicCellStyle.Name = "defaultStyle" GcCalendarGrid1.Styles.Add(dynamicCellStyle) GcCalendarGrid1.ScrollIntoView(New DateTime(2014, 1, 1)) End Sub Private Function condition(context As CellStyleContext) Dim cellStyle As New CalendarCellStyle() If context.IsHoliday Then If context.GcCalendarGrid.Content(context.CellPosition.[Date]).Tag IsNot Nothing AndAlso context.GcCalendarGrid.Content(context.CellPosition.[Date]).Tag.ToString() = "私的な休日" Then cellStyle.ForeColor = Color.Blue Else cellStyle.ForeColor = Color.Red End If End If Return cellStyle End Function
using GrapeCity.Win.CalendarGrid; private void Form1_Load(object sender, EventArgs e) { // 既定のスタイルを削除する gcCalendarGrid1.Styles.Clear(); // 既定のスタイルによる休日 gcCalendarGrid1.Holidays.Add(new DateTime(2014, 1, 1), "元日"); gcCalendarGrid1.Holidays.Add(new DateTime(2014, 1, 2), "年始休業"); gcCalendarGrid1.Content[new DateTime(2014, 1, 2)].Tag = "私的な休日"; var dynamicCellStyle = new CalendarDynamicCellStyle(new DynamicCellStyleCondition((context) => { var cellStyle = new CalendarCellStyle(); if (context.IsHoliday) { if((context.GcCalendarGrid.Content[context.CellPosition.Date].Tag != null) && (context.GcCalendarGrid.Content[context.CellPosition.Date].Tag.ToString() == "私的な休日")) { cellStyle.ForeColor = Color.Blue; } else { cellStyle.ForeColor = Color.Red; } } return cellStyle; })); dynamicCellStyle.Name = "defaultStyle"; gcCalendarGrid1.Styles.Add(dynamicCellStyle); gcCalendarGrid1.ScrollIntoView(new DateTime(2014, 1, 1)); }