Control.Size Eigenschap
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee haalt u de hoogte en breedte van het besturingselement op of stelt u deze in.
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
Waarde van eigenschap
De Size hoogte en breedte van het besturingselement in pixels.
Voorbeelden
In het volgende codevoorbeeld wordt een Button formulier toegevoegd en worden enkele algemene eigenschappen ervan ingesteld. In het voorbeeld wordt de knop in de rechterbenedenhoek van het formulier verankerd, zodat de relatieve positie behouden blijft wanneer het formulier wordt gewijzigd. Vervolgens stelt u de knop in BackgroundImage en wijzigt u de grootte van de knop op dezelfde grootte als de Image. In het voorbeeld wordt vervolgens de TabStoptrue eigenschap ingesteld TabIndex op en ingesteld. Ten slotte wordt er een gebeurtenis-handler toegevoegd om de Click gebeurtenis van de knop af te handelen. In dit voorbeeld moet u een ImageList naam imageList1hebben.
// 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
Opmerkingen
Omdat de klasse Size een waardetype is (Structure in Visual Basic, wordt struct in Visual C# geretourneerd door waarde, wat betekent dat het openen van de eigenschap een kopie van de grootte van het besturingselement retourneert. Het aanpassen van de Width of Height eigenschappen van de Size geretourneerde eigenschap is dus niet van invloed op het Width besturingselement of Height het besturingselement. Als u het besturingselement wilt Width aanpassen, moet u de eigenschap of Height eigenschap van het besturingselement Width instellen of de Height eigenschap instellen met een nieuwe Size.Size
Note
Als u betere prestaties wilt behouden, stelt u het Size besturingselement niet in de constructor in. De voorkeursmethode is het overschrijven van de DefaultSize eigenschap.
Note
Op Windows Server 2003-systemen wordt de grootte van een Form beperkt door de maximale pixelbreedte en hoogte van de monitor.