Control.Size Eigenschaft

Definition

Ruft die Höhe und Breite des Steuerelements ab oder legt diese fest.

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

Eigenschaftswert

Size

Die Size, die die Höhe und Breite des Steuerelements in Pixel darstellt.

Beispiele

Im folgenden Codebeispiel wird einem Formular ein Button hinzugefügt und einige der allgemeinen Eigenschaften festgelegt. Im Beispiel wird die Schaltfläche in der unteren rechten Ecke des Formulars verankert, sodass ihre relative Position beibehalten wird, während die Größe des Formulars geändert wird. Als Nächstes wird festgelegt BackgroundImage und die Größe der Schaltfläche auf die gleiche Größe wie die Imagegeändert. Im Beispiel wird dann auf TabStoptrue und die TabIndex -Eigenschaft festgelegt. Schließlich wird ein Ereignishandler hinzugefügt, um das Click Ereignis der Schaltfläche zu behandeln. Dieses Beispiel erfordert, dass Sie über einen ImageList namens verfügen imageList1.

   // 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

Hinweise

Da die Size Klasse ein Werttyp (Structure in Visual Basic, in Visual C#) ist, struct wird sie vom Wert zurückgegeben, was bedeutet, dass der Zugriff auf die -Eigenschaft eine Kopie der Größe des Steuerelements zurückgibt. Daher wirkt sich das Anpassen der Width Eigenschaften oder Height der Size von dieser Eigenschaft zurückgegebenen eigenschaften nicht auf das Width oder Height des -Steuerelements aus. Zum Anpassen des Width oder Height des Steuerelements müssen Sie die -Eigenschaft oder Height -Eigenschaft des Steuerelements Width oder die Size -Eigenschaft mit einem neuen Sizefestlegen.

Hinweis

Um eine bessere Leistung zu gewährleisten, legen Sie die Size eines Steuerelements nicht im Konstruktor fest. Die bevorzugte Methode besteht darin, die DefaultSize -Eigenschaft zu überschreiben.

Hinweis

Auf Windows Server 2003-Systemen wird die Größe eines Form durch die maximale Pixelbreite und -höhe des Monitors eingeschränkt.

Gilt für:

Weitere Informationen