Changes

Hiding and Showing Forms in C Sharp

1,004 bytes removed, 16:48, 28 January 2008
Hiding and Closing a Windows Form in C#
</pre>
== Hiding and Closing a Windows Form in C# ==
 
Now that we have displayed the form we now need a way to hide it. To achieve this we will add code to the Click event of the button contained in our subForm. Select the ''subForm.cs'' tab in Visual Studio and double click on the button in out form. Since we will be hiding the form in which the button is contained we simply call the ''Hide()'' method of the ''this'' object reference:
 
<pre>
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
}
</pre>
 
it is important to note at this point that we are only hiding the form we have created. This means that the object still exists in memory and as such is using system resources. To discard the form and release any resources assigned to it simply use the ''Close()'' method in place of the ''Hide()'' method in the event code:
 
<pre>
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
</pre>