Control.Size Eigenschaft
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Dient zum Abrufen oder Festlegen der Höhe und Breite des Steuerelements.
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
Der Size Wert, der die Höhe und Breite des Steuerelements in Pixel darstellt.
Beispiele
Im folgenden Codebeispiel wird einem Formular ein Button Formular hinzugefügt und einige seiner allgemeinen Eigenschaften festgelegt. Im Beispiel wird die Schaltfläche an der unteren rechten Ecke des Formulars verankert, sodass die relative Position beibehalten wird, während die Größe des Formulars geändert wird. Als Nächstes legt sie die BackgroundImage Schaltfläche auf dieselbe Größe fest und ändert sie auf die gleiche Größe wie die Image. Anschließend legt das Beispiel die TabStop Eigenschaft auf true und legt sie TabIndex fest. Schließlich wird ein Ereignishandler zum Behandeln des Click Ereignisses der Schaltfläche hinzugefügt. Dieses Beispiel erfordert, dass Sie einen ImageList Namen imageList1haben.
// 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 es sich bei der Size Klasse um einen Werttyp handelt (Structure in Visual Basic, struct in Visual C#), wird sie durch einen Wert zurückgegeben, was bedeutet, dass der Zugriff auf die Eigenschaft eine Kopie der Größe des Steuerelements zurückgibt. Das Anpassen der WidthSize von Height dieser Eigenschaft zurückgegebenen Eigenschaften wirkt sich also nicht auf das Width Steuerelement oder Height das Steuerelement aus. Um das Width Steuerelement oder Height das Steuerelement anzupassen, müssen Sie die Eigenschaft oder Height eigenschaft des Steuerelements Width festlegen oder die Size Eigenschaft mit einer neuen Sizefestlegen.
Hinweis
Um eine bessere Leistung zu gewährleisten, legen Sie das Size Steuerelement in seinem Konstruktor nicht fest. Die bevorzugte Methode besteht darin, die DefaultSize Eigenschaft außer Kraft zu setzen.
Hinweis
Unter Windows Server 2003-Systemen wird die Größe eines Form Elements durch die maximale Pixelbreite und -höhe des Monitors eingeschränkt.