Sdílet prostřednictvím


Control.Size Vlastnost

Definice

Získá nebo nastaví výšku a šířku ovládacího prvku.

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

Hodnota vlastnosti

Představuje Size výšku a šířku ovládacího prvku v pixelech.

Příklady

Následující příklad kódu přidá Button do formuláře a nastaví některé její společné vlastnosti. Příklad ukotvení tlačítka do pravého dolního rohu formuláře, aby při změně velikosti formuláře zachová jeho relativní pozici. Dále nastaví BackgroundImage tlačítko a změní velikost tlačítka na stejnou velikost jako Image. Příklad pak nastaví TabStop na true a nastaví TabIndex vlastnost. Nakonec přidá obslužnou rutinu události pro zpracování Click události tlačítka. Tento příklad vyžaduje, abyste měli ImageList název 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

Poznámky

Vzhledem k tomu, že Size třída je typ hodnoty (Structure v jazyce Visual Basic, struct v jazyce Visual C#), je vrácena hodnotou, což znamená, že přístup k vlastnosti vrátí kopii velikosti ovládacího prvku. Úpravou Width nebo Height vlastností vrácených Size z této vlastnosti tedy nebude mít vliv na Width ovládací prvek ani Height na ovládací prvek. Chcete-li upravit Width ovládací prvek nebo Height ovládací prvek, musíte nastavit jeho Width vlastnost Height nebo nastavit Size vlastnost novým Size.

Poznámka:

Chcete-li zachovat lepší výkon, nenastavujte Size ovládací prvek v jeho konstruktoru. Upřednostňovanou metodou je přepsání DefaultSize vlastnosti.

Poznámka:

V systémech Windows Server 2003 je velikost Form monitoru omezená maximální šířkou a výškou pixelů.

Platí pro

Viz také