Control.Size Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene o imposta l'altezza e la larghezza del controllo.
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
Valore della proprietà
Oggetto Size che rappresenta l'altezza e la larghezza del controllo in pixel.
Esempio
Nell'esempio di codice seguente viene aggiunto un oggetto Button a una maschera e vengono impostate alcune delle relative proprietà comuni. Nell'esempio il pulsante viene ancorato all'angolo inferiore destro del form in modo da mantenere la relativa posizione relativa man mano che viene ridimensionata la maschera. Imposta quindi e BackgroundImage ridimensiona il pulsante con le stesse dimensioni di Image. Nell'esempio viene quindi impostato su TabStoptrue e viene impostata la TabIndex proprietà . Infine, aggiunge un gestore eventi per gestire l'evento Click del pulsante. Questo esempio richiede che sia presente un ImageList oggetto denominato 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
Commenti
Poiché la Size classe è un tipo valore (Structure in Visual Basic, struct in Visual C#), viene restituita per valore, ovvero l'accesso alla proprietà restituisce una copia delle dimensioni del controllo. Pertanto, la regolazione delle Width proprietà o Height dell'oggetto Size restituito da questa proprietà non influirà sull'oggetto Width o Height sul controllo . Per regolare l'oggetto Width o Height del controllo, è necessario impostare la proprietà o Height il controllo Width oppure impostare la Size proprietà con un nuovo Sizeoggetto .
Annotazioni
Per mantenere prestazioni migliori, non impostare l'oggetto Size di un controllo nel relativo costruttore. Il metodo preferito consiste nell'eseguire l'override della DefaultSize proprietà .
Annotazioni
Nei sistemi Windows Server 2003, le dimensioni di un Form oggetto sono limitate dalla larghezza massima e dall'altezza massima del monitor.