I would like to call a method to clear the controls inside a form.
eg. i am having textboxes,comboboxes,buttons....functions,methods etc in a form. Now i would like to use a method to clear everything that is in the form, making it into the default state. is there a way i can go about doing it

VS.Net 2005 how to clear form?
Mark A. Richman
Not sure what you mean by clearing the form. If you want to hide the controls that you can set the the Visible property to false e.g. textBox1.Visible = false;
If you want to clear the contents of the controls than you've to iterate over all the controls within the collection & set the appropriate values e.g. textBox1.Text = string.Empty or as below
ControlCollection coll = Form1.ControlCollection;foreach (Control control in coll) {if (control.GetType() == typeof(TextBox)){ control.Text = string.Empty; }}Manav
Alvin tiow
this will clear all the controls in the form
this.Controls.Clear();Blake01
rwerner
Error 1 'System.Windows.Forms.Control.ControlCollection' is a 'type', which is not valid in the given context C:\Documents and Settings\student\My Documents\Visual Studio 2005\Projects\VCamAPP\VCamAPP\Screen.cs 12 55 VCamAPP
i receive this error when i added into a class the following
Control.ControlCollection coll = formScr1.ControlCollection;
coll.Clear();
x0ras
You can use something like below (i.e. get collection of controls in your form & call clear() on the collection)
ControlCollection coll = Form1.ControlCollection;coll.Clear();
Manav