GrapeCity CalendarGrid for Windows Forms 2.0J
サンプルコード(CalendarGcTextBoxCellType)

KeyDownイベントの処理

CalendarGcTextBoxCellTypeでGcTextBox.KeyDownイベントと同様の処理を行うには、GcCalendarGrid.EditingControlShowingイベントでセルの編集コントロールに対してイベントを割り当てます。

Imports GrapeCity.Win.CalendarGrid
Imports InputManCell = GrapeCity.Win.CalendarGrid.InputMan
Imports CalendarGridInputMan = GrapeCity.Win.CalendarGrid.Editors

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim today As DateTime = DateTime.Today
    GcCalendarGrid1.Content(today).Rows(1).Cells(0).CellStyle.BackColor = Color.Azure
    GcCalendarGrid1.Content(today).Rows(1).Cells(0).CellType = New InputManCell.CalendarGcTextBoxCellType()

    AddHandler GcCalendarGrid1.EditingControlShowing, AddressOf GcCalendarGrid1_EditingControlShowing
End Sub

Private Sub GcCalendarGrid1_EditingControlShowing(sender As Object, e As CalendarEditingControlShowingEventArgs)
    Dim today As DateTime = DateTime.Today
    Dim targetCellPosition As New CalendarCellPosition(today, 1, 0)
    Dim gcCalendarGrid As GcCalendarGrid = DirectCast(sender, GcCalendarGrid)
    If gcCalendarGrid.CurrentCellPosition = targetCellPosition Then
        Dim gcTextBox As CalendarGridInputMan.GcTextBox = DirectCast(e.Control, CalendarGridInputMan.GcTextBox)
        If Not gcTextBox Is Nothing Then
            RemoveHandler gcTextBox.KeyDown, AddressOf GcTextBox_KeyDown
            AddHandler gcTextBox.KeyDown, AddressOf GcTextBox_KeyDown
        End If
    End If
End Sub

Private Sub GcTextBox_KeyDown(sender As Object, e As KeyEventArgs)
    Console.WriteLine(e.KeyCode)
End Sub
using GrapeCity.Win.CalendarGrid;
using InputManCell = GrapeCity.Win.CalendarGrid.InputMan;
using CalendarGridInputMan = GrapeCity.Win.CalendarGrid.Editors;

private void Form1_Load(object sender, EventArgs e)
{
    var today = DateTime.Today;
    gcCalendarGrid1.Content[today].Rows[1].Cells[0].CellStyle.BackColor = Color.Azure;
    gcCalendarGrid1.Content[today].Rows[1].Cells[0].CellType = new InputManCell.CalendarGcTextBoxCellType();
    gcCalendarGrid1.EditingControlShowing += gcCalendarGrid1_EditingControlShowing;
}

private void gcCalendarGrid1_EditingControlShowing(object sender, CalendarEditingControlShowingEventArgs e)
{
    var today = DateTime.Today;
    var targetCellPosition = new CalendarCellPosition(today, 1, 0);
    var gcCalendarGrid = sender as GcCalendarGrid;
    if (gcCalendarGrid.CurrentCellPosition == targetCellPosition)
    {
        var gcTextBox = e.Control as CalendarGridInputMan.GcTextBox;
        if (gcTextBox != null)
        {
            gcTextBox.KeyDown -= gcTextBox_KeyDown;
            gcTextBox.KeyDown += gcTextBox_KeyDown;
        }
    }
}

private void gcTextBox_KeyDown(object sender, KeyEventArgs e)
{
    Console.WriteLine(e.KeyCode);
}
参照

 

 


© 2008 GrapeCity inc. All rights reserved.