Want to see what people are talking about? See the latest forum posts.
*/

Other Views

corner
*/

WinForm FAQ - Minimizing, Maximizing, and Restoring a Form

How do I minimize, maximize and restore my form programmatically?

You can minimize, maximize and restore the form by setting the WindowState property of the form. The following code example will minimize the form, wait for 2 seconds, restore the form, wait for 2 seconds and then maximize the form. I have written this code on the a button’s Click event.

C# Version

private void button1_Click(object sender, System.EventArgs e)
{
// Minimize the form window
	this.WindowState = FormWindowState.Minimized;
	Thread.Sleep(2000);	// wait for 2 seconds
	// Restore the form window
	this.WindowState = FormWindowState.Normal;
			
	Thread.Sleep(2000);	// wait for 2 seconds
	// Maximize the form window
	this.WindowState = FormWindowState.Maximized;
}


VB.NET Version

Private Sub Button1_Click(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) _
Handles Button1.Click
' Minimize the form window
      Me.WindowState = FormWindowState.Minimized
      Thread.Sleep(2000)  ' wait for 2 seconds
      ' Restore the form window
      Me.WindowState = FormWindowState.Normal
      Thread.Sleep(2000)  ' wait for 2 seconds
      ' Maximize the form window
      Me.WindowState = FormWindowState.Maximized
End Sub


Note that the above code snippet is using the System.Threading.Thread class’ Sleep method to suspend the form for 2 seconds. Hence, you would be required to include the System.Threading namespace to your form class source code.

C# Version

Using System.Threading;


VB.NET Version

Imports System.Threading


Index
corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.
Resource Listings