Form.WindowState Form.WindowState Form.WindowState Form.WindowState Property

定义

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

public:
 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 code 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. 这反映在HeightLeftTop,和Width属性设置。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.

适用于

另请参阅