How to clear all Textboxes on a Form in C# or VB.NET

To clear all Textboxes on a Form in C# or VB.NET you can use the Extensions method in the snippet below.

Sample C#

public static void ClearTextboxes(this Form form)
{
	foreach (var item in form.Controls.OfType<TextBox>())
	{
		item.Text = string.Empty;
	}
}

Sample VB.NET

<System.Runtime.CompilerServices.Extension> _
Public Sub ClearTextboxes(form As Form)
	For Each item As TextBox In form.Controls.OfType(Of TextBox)()
		item.Text = String.Empty
	Next
End Sub

One thought on “How to clear all Textboxes on a Form in C# or VB.NET

Leave a Reply