PowerTools CalendarGrid for Windows Forms 1.0J
週末を非表示にする

週スタイルのカレンダーで週末(土曜日と日曜日)を非表示にするには、CalendarWeekView.ShowWeekendプロパティをFalseに設定します。

Imports GrapeCity.Win.CalendarGrid

Dim weekView As New CalendarWeekView()
weekView.ShowWeekend = False
GcCalendarGrid1.CalendarView = weekView
using GrapeCity.Win.CalendarGrid;

CalendarWeekView weekView = new CalendarWeekView();
weekView.ShowWeekend = false;
gcCalendarGrid1.CalendarView = weekView;

任意の曜日を非表示にするには、LayoutSettings.SetHorizontalVisibleメソッドを使用して、実行時に表示される列のインデックスから非表示にしたい列をFalseに設定します。たとえば、左端に表示あsれているのが日曜日のとき(GcCalendarGrid.DateFormatInfo.FirstDayOfWeekがSundayのとき)、水曜日を非表示にするには日曜日を0として3番目の列を非表示にします。

Dim weekView As New CalendarWeekView()
GcCalendarGrid1.CalendarView = weekView
GcCalendarGrid1.LayoutSettings.SetHorizontalVisible(3, False)
using GrapeCity.Win.CalendarGrid;

CalendarWeekView weekView = new CalendarWeekView();
gcCalendarGrid1.CalendarView = weekView;
gcCalendarGrid1.LayoutSettings.SetHorizontalVisible(3, false);

曜日自体を非表示にするのではなく、曜日のスペースを保持したまま予定だけを空欄にするには、たとえば次のような方法があります。この方法では、特定の日のセルを結合して他の人の違いを明確にします。

Imports GrapeCity.Win.CalendarGrid

Dim weekView As New CalendarWeekView()
GcCalendarGrid1.CalendarView = weekView
GcCalendarGrid1.FirstDateInView = New DateTime(2014, 6, 1)
GcCalendarGrid1.Content(new DateTime(2014, 6, 4)).Rows(0).Cells(0).RowSpan = 4
GcCalendarGrid1.Content(new DateTime(2014, 6, 4)).Rows(0).Cells(0).DateFormat = ""
GcCalendarGrid1.Content(new DateTime(2014, 6, 4)).Rows(0).Cells(0).Value = "定休日"
GcCalendarGrid1.Content(new DateTime(2014, 6, 4)).Rows(0).Cells(0).CellStyle.BackColor = Color.WhiteSmoke
GcCalendarGrid1.Content(new DateTime(2014, 6, 4)).Rows(0).Cells(0).CellStyle.Alignment = CalendarGridContentAlignment.MiddleCenter
using GrapeCity.Win.CalendarGrid;

var weekView = new CalendarWeekView();
gcCalendarGrid1.CalendarView = weekView;gcCalendarGrid1.FirstDateInView = new DateTime(2014, 6, 1);
gcCalendarGrid1.Content[new DateTime(2014, 6, 4)].Rows[0].Cells[0].RowSpan = 4;
gcCalendarGrid1.Content[new DateTime(2014, 6, 4)].Rows[0].Cells[0].DateFormat = "";
gcCalendarGrid1.Content[new DateTime(2014, 6, 4)].Rows[0].Cells[0].Value = "定休日";
gcCalendarGrid1.Content[new DateTime(2014, 6, 4)].Rows[0].Cells[0].CellStyle.BackColor = Color.WhiteSmoke;
gcCalendarGrid1.Content[new DateTime(2014, 6, 4)].Rows[0].Cells[0].CellStyle.Alignment = CalendarGridContentAlignment.MiddleCenter;

あるいは、ある曜日を表示しつつ、この曜日の操作を禁止するには、次のようにGcCalendarGrid.CurrentCellPositionChangingイベントを使って移動を禁止することができます。次のコードは日曜日への移動を禁止します。

Private Sub GcCalendarGrid1_CurrentCellPositionChanging(sender As Object, e As _
        GrapeCity.Win.CalendarGrid.CalendarCellPositionChangingEventArgs) Handles _
        GcCalendarGrid1.CurrentCellPositionChanging

    If e.NewCellPosition.Date.DayOfWeek = DayOfWeek.Sunday Then
        e.Cancel = True
    End If
End Sub
private void gcCalendarGrid1_CurrentCellPositionChanging(object sender, CalendarCellPositionChangingEventArgs e)
{
    if (e.NewCellPosition.Date.DayOfWeek == DayOfWeek.Sunday)
    {
        e.Cancel = true;
    }
}
参照

 

 


© 2014 GrapeCity inc. All rights reserved.