// 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