イベント ハンドラが、このイベントに関連するデータを含む、TextChangingEventArgs 型の引数を受け取りました。次の TextChangingEventArgs プロパティには、このイベントの固有の情報が記載されます。
プロパティ | 解説 |
---|
Cancel | テキスト変更動作をキャンセルするか、しないかを取得または設定します。 |
Result | コントロールに設定されようとしているテキストを取得します。 |
次のコードは TextChanging イベントを発生させる方法を示します。この例では、
TextChangingEventArgs.Result が無効な文字列の場合に入力をキャンセルします。
// Please use the following namespace
// using System.Windows.Forms;
// using GrapeCity.Win.Editors;
public void WireTextChangingEvent()
{
// Create an instance of a GcTextBox control.
GcTextBox gcTextBox1 = new GcTextBox();
// Wire the TextChanging event.
gcTextBox1.TextChanging += new TextChangingEventHandler(OnTextBoxTextChanging);
}
private void OnTextBoxTextChanging(object sender, TextChangingEventArgs e)
{
// If the text change result will be string.Empty or null, cancel the text change process.
if (string.IsNullOrEmpty(e.Result))
{
e.Cancel = true;
}
}
' Please use the following namespace
' Imports System.Windows.Forms;
' Imports GrapeCity.Win.Editors;
Public Sub WireTextChangingEvent()
' Create an instance of a GcTextBox control.
Dim gcTextBox1 As New GcTextBox()
' Wire the TextChanging event.
AddHandler gcTextBox1.TextChanging, AddressOf OnTextBoxTextChanging
End Sub
Private Sub OnTextBoxTextChanging(ByVal sender As Object, ByVal e As TextChangingEventArgs)
' If the text change result will be string.Empty or null, cancel the text change process.
If String.IsNullOrEmpty(e.Result) Then
e.Cancel = True
End If
End Sub