TextBoxBase.Clear Method ()


Clears all text from the text box control.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

member Clear : unit -> unit

You can use this method to clear the contents of the control instead of assigning the Text property an empty string.

The following code example uses TextBox, a derived class, to create an event handler for the TextChanged event. The code within the event handler restricts data to numbers. After text has been entered in the control, the code determines if the text entered is a number. If the text is not a number, the code clears the text from the control and a MessageBox is displayed to alert the user that only numbers are accepted. The example requires that a Boolean variable named flag and a TextBox control called textBox1 are defined outside of this method. This example demonstrates how to use a flag variable to avoid a cascading event in the TextChanged event.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top