PowerTools InputMan for Windows Forms 8.0J
Clear メソッド (EditBase)
使用例 

コントロールの内容をクリアします。
構文
Public Overridable Sub Clear() 
public virtual void Clear()
解説
Clear メソッドは、Text プロパティを空の文字列に初期化します。 ReadOnly プロパティがTrueに設定されていると、 コントロールの内容は変更されません。
使用例
TextChanged イベントと連携するイベント処理を利用する GcTextBox コントロールを作成するコード例を次に示します。
//  Please use the following namespace
//  using System.Windows.Forms;
//  using GrapeCity.Win.Editors;

private bool flag;
public void WireTextChangedEvent()
{
    // Create an instance of a GcTextBox control.
    GcTextBox gcTextBox1 = new GcTextBox();
    // Wire the TextChanging event.
    gcTextBox1.TextChanged += new EventHandler(GcTextBox_TextChangedHandler);
}

private void GcTextBox_TextChangedHandler(System.Object sender, System.EventArgs e)
{
    GcTextBox gcTextBox1 = sender as GcTextBox;
    long val;
    // Check the flag to prevent code re-entry. 
    if (flag == false)
    {
        // Set the flag to True to prevent re-entry of the code below.
        flag = true;
        // Determine if the text of the control is a number.
        try
        {
            // Attempt to convert to long
            val = System.Convert.ToInt64(gcTextBox1.Text);
        }
        catch
        {
            // Display a message box and clear the contents if not a number.
            MessageBox.Show("The text is not a valid number. Please re-enter");
            // Clear the contents of the text box to allow re-entry.
            gcTextBox1.Clear();
        }
        // Reset the flag so other TextChanged events are processed correctly.
        flag = false;
    }
}
'  Please use the following namespace
'  Imports System.Windows.Forms;
'  Imports GrapeCity.Win.Editors;

Private flag As Boolean
Public Sub WireTextChangedEvent()
    ' Create an instance of a GcTextBox control.
    Dim gcTextBox1 As New GcTextBox()
    ' Wire the TextChanging event.
    AddHandler gcTextBox1.TextChanged, AddressOf GcTextBox_TextChangedHandler
End Sub

Private Sub GcTextBox_TextChangedHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Dim gcTextBox1 As GcTextBox = TryCast(sender, GcTextBox)
    Dim val As Long
    ' Check the flag to prevent code re-entry. 
    If flag = False Then
        ' Set the flag to True to prevent re-entry of the code below.
        flag = True
        ' Determine if the text of the control is a number.
        Try
            ' Attempt to convert to long
            val = System.Convert.ToInt64(gcTextBox1.Text)
        Catch
            ' Display a message box and clear the contents if not a number.
            MessageBox.Show("The text is not a valid number. Please re-enter")
            ' Clear the contents of the text box to allow re-entry.
            gcTextBox1.Clear()
        End Try
        ' Reset the flag so other TextChanged events are processed correctly.
        flag = False
    End If
End Sub
参照

EditBase クラス
EditBase メンバ
Paste メソッド
Copy メソッド
Cut メソッド
Undo メソッド
CanUndo プロパティ

 

 


© 2004-2015 GrapeCity inc. All rights reserved.