Form.Size 属性

定义

获取或设置窗体的大小。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 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 属性来调整窗体的大小,并根据桌面坐标定位该窗体,或使用 Control 类的 Bounds 属性基于屏幕设置窗体的大小和位置。一致.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 设备上,可以通过将 FormBorderStyle 设置为 None 并删除任何 MainMenu 控件来创建一个可调整大小的窗口。On Pocket PC devices, you can create a resizable window by setting FormBorderStyle to None and removing any MainMenu control. 在 SmartPhone 设备上,你永远不能调整 Form 大小-它将始终填充整个屏幕。On SmartPhone devices, you can never resize a Form - it will always fill the entire screen.

适用于

另请参阅