Form.Size Form.Size Form.Size Form.Size Property

定义

获取或设置窗体的大小。Gets or sets the size of the form.

public:
 property System::Drawing::Size Size { System::Drawing::Size get(); void set(System::Drawing::Size value); };
public System.Drawing.Size Size { get; set; }
member this.Size : System.Drawing.Size with get, set
Public Property Size As Size

属性值

Size,它表示窗体的大小。A Size that represents the size of the form.

示例

下面的代码示例演示如何创建带有 75%的不透明度级别显示的窗体。The following code example demonstrates how to create a form that is displayed with an opacity level of 75 percent. 示例代码将创建新的窗体,位于与屏幕的中央Opacity属性设置为更改窗体的不透明度级别。The example code creates a new form that is positioned in the center of the screen with an Opacity property set to change the opacity level of the form. 示例代码还设置Size属性以提供更大大小超过默认大小的窗体的窗体。The example code also sets the Size property to provide a larger sized form than the default size of the form. 此示例需要在此示例中定义的方法从另一种形式的事件处理程序或其他方法中调用。This example requires that the method defined in this example is called from another form in an event handler or other method.

private:
   void CreateMyOpaqueForm()
   {
      // Create a new form.
      Form^ form2 = gcnew Form;

      // Set the text displayed in the caption.
      form2->Text = "My Form";

      // Set the opacity to 75%.
      form2->Opacity = .75;

      // Size the form to be 300 pixels in height and width.
      form2->Size = System::Drawing::Size( 300, 300 );

      // Display the form in the center of the screen.
      form2->StartPosition = FormStartPosition::CenterScreen;

      // Display the form as a modal dialog box.
      form2->ShowDialog();
   }
private void CreateMyOpaqueForm()
{
   // Create a new form.
   Form form2 = new Form();
   // Set the text displayed in the caption.
   form2.Text = "My Form";
   // Set the opacity to 75%.
   form2.Opacity = .75;
   // Size the form to be 300 pixels in height and width.
   form2.Size = new Size(300,300);
   // Display the form in the center of the screen.
   form2.StartPosition = FormStartPosition.CenterScreen;

   // Display the form as a modal dialog box.
   form2.ShowDialog();
}
Private Sub CreateMyOpaqueForm()
   ' Create a new form.
   Dim form2 As New Form()
   ' Set the text displayed in the caption.
   form2.Text = "My Form"
   ' Set the opacity to 75%.
   form2.Opacity = 0.75
   ' Size the form to be 300 pixels in height and width.
   form2.Size = New Size(300, 300)
   ' Display the form in the center of the screen.
   form2.StartPosition = FormStartPosition.CenterScreen

   ' Display the form as a modal dialog box.
   form2.ShowDialog()
End Sub

注解

此属性可以设置而不是设置同时设置高度和宽度 (以像素为单位) 的窗体HeightWidth属性单独。This property allows you to set both the height and width (in pixels) of the form at the same time instead of setting the Height and Width properties individually. 如果你想要设置的大小和窗体的位置,则可以使用DesktopBounds属性以调整大小和定位该窗体基于桌面坐标或使用Bounds属性的Control类来设置的大小和位置的窗体根据屏幕坐标inates。If you want to set the size and location of a form, you can use the DesktopBounds property to size and locate the form based on desktop coordinates or use the Bounds property of the Control class to set the size and location of the form based on screen coordinates.

备注

此属性的最大值受限制的窗体在其运行的屏幕分辨率。The maximum value of this property is limited by the resolution of the screen on which the form runs. 每个屏幕维度 (水平 + 12 和垂直 + 12) 不能大于 12 像素值。The value cannot be greater than 12 pixels over each screen dimension (horizontal + 12 and vertical + 12).

备注

在 Pocket PC 设备,可以创建可调整大小窗口通过设置FormBorderStyleNone和删除任何MainMenu控件。On Pocket PC devices, you can create a resizable window by setting FormBorderStyle to None and removing any MainMenu control. 可以在智能手机设备上您永远不会调整大小Form-它将始终填充整个屏幕。On SmartPhone devices, you can never resize a Form - it will always fill the entire screen.

适用于

另请参阅