Export (0) Print
Expand All
2 out of 3 rated this helpful - Rate this topic

Form.WindowState Property

Gets or sets the form's window state.

[Visual Basic]
Public Property WindowState As FormWindowState
[C#]
public FormWindowState WindowState {get; set;}
[C++]
public: __property FormWindowState get_WindowState();
public: __property void set_WindowState(FormWindowState);
[JScript]
public function get WindowState() : FormWindowState;
public function set WindowState(FormWindowState);

Property Value

A FormWindowState that represents the window state of the form. The default is FormWindowState.Normal.

Exceptions

Exception Type Condition
InvalidEnumArgumentException The value specified is outside the range of valid values.

Remarks

Before a form is displayed, the WindowState property is always set to FormWindowState.Normal, regardless of its initial setting. This is reflected in the Height, Left, Top, and Width property settings. If a form is hidden after it has been shown, these properties reflect the previous state until the form is shown again, regardless of any changes made to the WindowState property.

Example

[Visual Basic, C#, C++] The following example demonstrates how to create a top-most form. The example creates two forms, one that is maximized and one which will be displayed as a top-most form. The first form, named bottomForm, is displayed maximized, using the WindowState property, to better demonstrate the abilities of the top-most form. The second form, named topMostForm, sets the TopMost property to true to display the form as a top-most form. When this code is run, clicking on the maximized form will not cause the top-most form to be displayed below the maximized form. The example assumes that the method defined in the example is called from another form.

[Visual Basic] 
Private Sub CreateMyTopMostForm()
   ' Create lower form to display.
   Dim bottomForm As New Form()
   ' Display the lower form Maximized to demonstrate effect of TopMost property.
   bottomForm.WindowState = FormWindowState.Maximized
   ' Display the bottom form.
   bottomForm.Show()
   ' Create the top most form.
   Dim topMostForm As New Form()
   ' Set the size of the form larger than the default size.
   topMostForm.Size = New Size(300, 300)
   ' Set the position of the top most form to center of screen.
   topMostForm.StartPosition = FormStartPosition.CenterScreen
   ' Display the form as top most form.
   topMostForm.TopMost = True
   topMostForm.Show()
End Sub 'CreateMyTopMostForm

[C#] 
private void CreateMyTopMostForm()
{
   // Create lower form to display.
   Form bottomForm = new Form();
   // Display the lower form Maximized to demonstrate effect of TopMost property.
   bottomForm.WindowState = FormWindowState.Maximized;
   // Display the bottom form.
   bottomForm.Show();
   // Create the top most form.
   Form topMostForm = new Form();
   // Set the size of the form larger than the default size.
   topMostForm.Size = new Size(300,300);
   // Set the position of the top most form to center of screen.
   topMostForm.StartPosition = FormStartPosition.CenterScreen;
   // Display the form as top most form.
   topMostForm.TopMost = true;
   topMostForm.Show();
}

[C++] 
private:
   void CreateMyTopMostForm()
   {
      // Create lower form to display.
      Form* bottomForm = new Form();
      // Display the lower form Maximized to demonstrate effect of TopMost property.
      bottomForm->WindowState = FormWindowState::Maximized;
      // Display the bottom form.
      bottomForm->Show();
      // Create the top most form.
      Form* topMostForm = new Form();
      // Set the size of the form larger than the default size.
      topMostForm->Size = System::Drawing::Size(300,300);
      // Set the position of the top most form to center of screen.
      topMostForm->StartPosition = FormStartPosition::CenterScreen;
      // Display the form as top most form.
      topMostForm->TopMost = true;
      topMostForm->Show();
   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

Form Class | Form Members | System.Windows.Forms Namespace | FormWindowState

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.