// Creates a new TextBox control TextBox textBox = new TextBox(); // Sets the text of the TextBox control. textBox.Text = "Hello World!"; // Clears the text of the TextBox control textBox.Clear();
// Locates the TextBox control on a Windows form TextBox textBox = this.Controls["textBox1"] as TextBox; // Clears the text of the TextBox control textBox.Clear();In this example, we locate a previously created TextBox control on a Windows form using its name and the Controls collection. We then use the Clear method to erase all of the text from the TextBox. Package/Library: The System.Windows.Forms namespace is included in the .NET Framework, so this method is part of the .NET Framework Class Library.