共用方式為


Form.Size 屬性

定義

取得或設定表單的大小。

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

屬性值

A Size 代表表單的大小。

範例

以下範例示範如何建立一個不透明度為 75% 的表單。 範例程式碼會建立一個新表單,位於螢幕中央,並 Opacity 設定屬性以改變表單的不透明度等級。 範例程式碼也設定 Size 了屬性,使表單的大小比預設大小更大。 此範例要求本範例中定義的方法必須從事件處理程序或其他方法中的其他形式呼叫。

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 屬性。 如果你想設定表單的大小和位置,可以用 DesktopBounds 屬性根據桌面座標來調整表單大小和位置,或用 Bounds 類別的 Control 屬性根據螢幕座標設定表單的大小和位置。

備註

此特性的最大值受限於表單所運行螢幕的解析度。 每個螢幕尺寸(水平+12,垂直+12)的數值不得超過12像素。

備註

在 Pocket PC 裝置上,你可以透過設定 FormBorderStyleNone 移除任何 MainMenu 控制項來建立可調整大小的視窗。 在智慧型手機裝置上,你永遠無法調整 a 大小 Form ——它總是會填滿整個螢幕。

適用於

另請參閱