Control.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

プロパティ値

コントロールの高さと幅をピクセル単位で表す Size

次のコード例では、 Button をフォームに追加し、その共通プロパティの一部を設定します。 この例では、フォームの右下隅にボタンを固定して、フォームのサイズ変更時に相対的な位置を維持します。 次に、 を BackgroundImage 設定し、ボタンのサイズを と同じサイズに Image変更します。 次に、 を TabStoptrue 設定し、 プロパティを TabIndex 設定します。 最後に、ボタンのイベントを処理 Click するイベント ハンドラーを追加します。 この例では、 という名前imageList1の がImageList必要です。

   // Add a button to a form and set some of its common properties.
private:
   void AddMyButton()
   {
      // Create a button and add it to the form.
      Button^ button1 = gcnew Button;

      // Anchor the button to the bottom right corner of the form
      button1->Anchor = static_cast<AnchorStyles>(AnchorStyles::Bottom | AnchorStyles::Right);

      // Assign a background image.
      button1->BackgroundImage = imageList1->Images[ 0 ];

      // Specify the layout style of the background image. Tile is the default.
      button1->BackgroundImageLayout = ImageLayout::Center;

      // Make the button the same size as the image.
      button1->Size = button1->BackgroundImage->Size;

      // Set the button's TabIndex and TabStop properties.
      button1->TabIndex = 1;
      button1->TabStop = true;

      // Add a delegate to handle the Click event.
      button1->Click += gcnew System::EventHandler( this, &Form1::button1_Click );

      // Add the button to the form.
      this->Controls->Add( button1 );
   }
// Add a button to a form and set some of its common properties.
private void AddMyButton()
{
   // Create a button and add it to the form.
   Button button1 = new Button();

   // Anchor the button to the bottom right corner of the form
   button1.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);

   // Assign a background image.
   button1.BackgroundImage = imageList1.Images[0];

   // Specify the layout style of the background image. Tile is the default.
   button1.BackgroundImageLayout = ImageLayout.Center;
   
   // Make the button the same size as the image.
   button1.Size = button1.BackgroundImage.Size;

   // Set the button's TabIndex and TabStop properties.
   button1.TabIndex = 1;
   button1.TabStop = true;

   // Add a delegate to handle the Click event.
   button1.Click += new System.EventHandler(this.button1_Click);

   // Add the button to the form.
   this.Controls.Add(button1);
}
' Add a button to a form and set some of its common properties.
Private Sub AddMyButton()
   ' Create a button and add it to the form.
   Dim button1 As New Button()
   
   ' Anchor the button to the bottom right corner of the form
   button1.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
   
   ' Assign a background image.
   button1.BackgroundImage = imageList1.Images(0)

   ' Specify the layout style of the background image. Tile is the default.
   button1.BackgroundImageLayout = ImageLayout.Center
   
   ' Make the button the same size as the image.
   button1.Size = button1.BackgroundImage.Size
   
   ' Set the button's TabIndex and TabStop properties.
   button1.TabIndex = 1
   button1.TabStop = True

   ' Add a delegate to handle the Click event.
   AddHandler button1.Click, AddressOf Me.button1_Click
   
   ' Add the button to the form.
   Me.Controls.Add(button1)
End Sub

注釈

クラスは値型 Size (Structure Visual Basic では Visual C# では ) であるため、 struct 値によって返されます。つまり、 プロパティにアクセスすると、コントロールのサイズのコピーが返されます。 そのため、このプロパティから返される の プロパティまたは Height プロパティをSize調整Widthすると、 コントロールの または Height には影響Widthしません。 コントロールの または HeightWidth調整するには、コントロールの または Height プロパティをWidth設定するか、新しい Sizeを使用して プロパティを設定するSize必要があります。

Note

パフォーマンスを向上させるには、コンストラクターで コントロールの を Size 設定しないでください。 推奨される方法は、 プロパティを DefaultSize オーバーライドすることです。

Note

Windows Server 2003 システムでは、 のサイズは、モニターの Form 最大ピクセル幅と高さによって制限されます。

適用対象

こちらもご覧ください