Form.WindowState 属性


获取或设置一个值,该值指示窗体是最小化、最大化还是正常。Gets or sets a value that indicates whether form is minimized, maximized, or normal.

 property System::Windows::Forms::FormWindowState WindowState { System::Windows::Forms::FormWindowState get(); void set(System::Windows::Forms::FormWindowState value); };
public System.Windows.Forms.FormWindowState WindowState { get; set; }
member this.WindowState : System.Windows.Forms.FormWindowState with get, set
Public Property WindowState As FormWindowState


FormWindowState,它表示窗体是最小化、 最大化,还是正常。A FormWindowState that represents whether form is minimized, maximized, or normal. 默认值为 FormWindowState.NormalThe default is FormWindowState.Normal.


指定值不在有效值范围内。The value specified is outside the range of valid values.


下面的示例演示如何将 WindowState 设置为 "最大化"。The following example demonstrates how to set the WindowState to maximized. 创建窗体后,从 Shown 事件处理程序中调用该代码。The code is called from the Shown event handler after the form has been created.

private void Form1_Shown(object sender, EventArgs e)  
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;  
Private  Sub Form1_Shown(ByVal sender As Object, ByVal e As EventArgs)  
            Me.WindowState = System.Windows.Forms.FormWindowState.Maximized  
End Sub  


在显示窗体之前,WindowState 属性始终设置为 FormWindowState.Normal,而不考虑其初始设置。Before a form is displayed, the WindowState property is always set to FormWindowState.Normal, regardless of its initial setting. 这会反映在 HeightLeftTopWidth 属性设置中。This is reflected in the Height, Left, Top, and Width property settings. 如果窗体在显示后被隐藏,则这些属性将反映以前的状态,直到再次显示该窗体,而不考虑对 WindowState 属性所做的任何更改。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.