イベント ハンドラが、このイベントに関連するデータを含む、CalendarEditingControlShowingEventArgs 型の引数を受け取りました。次の CalendarEditingControlShowingEventArgs プロパティには、このイベントの固有の情報が記載されます。
プロパティ | 解説 |
---|
Control | 選択されているセルの値を編集するためにユーザーに表示されるコントロールを取得します。 |
次のサンプルコードは、セルエディタからの通知をサブスクライブする方法を示します。
using System;
using System.Windows.Forms;
using System.Drawing;
using GrapeCity.Win.CalendarGrid;
namespace CalendarGridSampleCode
{
class EditingControlShowingDemo : Form
{
GcCalendarGrid gcCalendarGrid = new GcCalendarGrid();
public EditingControlShowingDemo()
{
gcCalendarGrid.Template = this.CreateTemplate();
gcCalendarGrid.Dock = DockStyle.Fill;
gcCalendarGrid.EditMode = CalendarEditMode.EditOnEnter;
gcCalendarGrid.CurrentCellPosition = new CalendarCellPosition(DateTime.Today, 1, 0);
gcCalendarGrid.EditingControlShowing += gcCalendarGrid_EditingControlShowing;
this.Text = "EditingControlShowing Demo";
this.Controls.Add(gcCalendarGrid);
}
void gcCalendarGrid_EditingControlShowing(object sender, CalendarEditingControlShowingEventArgs e)
{
TextBox textBox = e.Control as TextBox;
if (textBox != null)
{
// Add TextChange event handler.
textBox.TextChanged -= textBox_TextChanged;
textBox.TextChanged += textBox_TextChanged;
}
}
private CalendarTemplate CreateTemplate()
{
CalendarTemplate calendarTemplate1 = new CalendarTemplate();
GrapeCity.Win.CalendarGrid.CalendarHeaderCellType calendarHeaderCellType1 = new GrapeCity.Win.CalendarGrid.CalendarHeaderCellType();
calendarTemplate1.RowCount = 2;
calendarTemplate1.RowHeaderColumnCount = 0;
calendarTemplate1.ColumnHeader.CellStyleName = "defaultStyle";
calendarHeaderCellType1.SupportLocalization = true;
calendarTemplate1.ColumnHeader.GetCell(0, 0).CellType = calendarHeaderCellType1;
calendarTemplate1.ColumnHeader.GetCell(0, 0).DateFormat = "{DayOfWeek}";
calendarTemplate1.ColumnHeader.GetCell(0, 0).CellStyle.Alignment = GrapeCity.Win.CalendarGrid.CalendarGridContentAlignment.MiddleCenter;
calendarTemplate1.Content.CellStyleName = "defaultStyle";
calendarTemplate1.Content.GetCell(0, 0).DateFormat = "d日";
calendarTemplate1.Content.GetCell(0, 0).DateFormatType = GrapeCity.Win.CalendarGrid.CalendarDateFormatType.DotNet;
return calendarTemplate1;
}
void textBox_TextChanged(object sender, EventArgs e)
{
Console.WriteLine("Editing control text changed.");
}
[STAThreadAttribute()]
public static void Main()
{
Application.EnableVisualStyles();
Application.Run(new EditingControlShowingDemo());
}
}
}
Imports System.Windows.Forms
Imports System.Drawing
Imports GrapeCity.Win.CalendarGrid
Namespace CalendarGridSampleCode
Class EditingControlShowingDemo
Inherits Form
Private gcCalendarGrid As New GcCalendarGrid()
Public Sub New()
gcCalendarGrid.Template = Me.CreateTemplate()
gcCalendarGrid.Dock = DockStyle.Fill
gcCalendarGrid.EditMode = CalendarEditMode.EditOnEnter
gcCalendarGrid.CurrentCellPosition = New CalendarCellPosition(DateTime.Today, 1, 0)
AddHandler gcCalendarGrid.EditingControlShowing, AddressOf gcCalendarGrid_EditingControlShowing
Me.Text = "EditingControlShowing Demo"
Me.Controls.Add(gcCalendarGrid)
End Sub
Private Sub gcCalendarGrid_EditingControlShowing(sender As Object, e As CalendarEditingControlShowingEventArgs)
Dim textBox As TextBox = TryCast(e.Control, TextBox)
If textBox IsNot Nothing Then
' Add TextChange event handler.
RemoveHandler textBox.TextChanged, AddressOf textBox_TextChanged
AddHandler textBox.TextChanged, AddressOf textBox_TextChanged
End If
End Sub
Private Function CreateTemplate() As CalendarTemplate
Dim calendarTemplate1 As New CalendarTemplate()
Dim calendarHeaderCellType1 As New GrapeCity.Win.CalendarGrid.CalendarHeaderCellType()
calendarTemplate1.RowCount = 2
calendarTemplate1.RowHeaderColumnCount = 0
calendarTemplate1.ColumnHeader.CellStyleName = "defaultStyle"
calendarHeaderCellType1.SupportLocalization = True
calendarTemplate1.ColumnHeader.GetCell(0, 0).CellType = calendarHeaderCellType1
calendarTemplate1.ColumnHeader.GetCell(0, 0).DateFormat = "{DayOfWeek}"
calendarTemplate1.ColumnHeader.GetCell(0, 0).CellStyle.Alignment = GrapeCity.Win.CalendarGrid.CalendarGridContentAlignment.MiddleCenter
calendarTemplate1.Content.CellStyleName = "defaultStyle"
calendarTemplate1.Content.GetCell(0, 0).DateFormat = "d日"
calendarTemplate1.Content.GetCell(0, 0).DateFormatType = GrapeCity.Win.CalendarGrid.CalendarDateFormatType.DotNet
Return calendarTemplate1
End Function
Private Sub textBox_TextChanged(sender As Object, e As EventArgs)
Console.WriteLine("Editing control text changed.")
End Sub
<STAThreadAttribute> _
Public Shared Sub Main()
Application.EnableVisualStyles()
Application.Run(New EditingControlShowingDemo())
End Sub
End Class
End Namespace