Control.Size Propiedad

Definición

Obtiene o establece el alto y el ancho del control.Gets or sets the height and width of the control.

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

Valor de propiedad

Size que representa el ancho y el alto del control en píxeles.The Size that represents the height and width of the control in pixels.

Ejemplos

En el ejemplo de código siguiente se agrega un Button a un formulario y se establecen algunas de sus propiedades comunes.The following code example adds a Button to a form and sets some of its common properties. En el ejemplo se delimita el botón en la esquina inferior derecha del formulario para que mantenga su posición relativa a medida que se cambia el tamaño del formulario.The example anchors the button to the bottom-right corner of the form so it keeps its relative position as the form is resized. A continuación, establece el BackgroundImage y cambia el tamaño del botón al mismo tamaño que el Image.Next it sets the BackgroundImage and resizes the button to the same size as the Image. A continuación, en el ejemplo se establece el TabStop en true y se establece la propiedad TabIndex.The example then sets the TabStop to true and sets the TabIndex property. Por último, agrega un controlador de eventos para controlar el evento Click del botón.Lastly, it adds an event handler to handle the Click event of the button. Este ejemplo requiere que tenga un ImageList denominado imageList1.This example requires that you have an ImageList named 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

Comentarios

Dado que la clase Size es un tipo de valor (Structure en Visual Basic, struct C#en visual), se devuelve por valor, lo que significa que el acceso a la propiedad devuelve una copia del tamaño del control.Because the Size class is a value type (Structure in Visual Basic, struct in Visual C#), it is returned by value, meaning accessing the property returns a copy of the size of the control. Por lo tanto, el ajuste de las propiedades Width o Height del Size devuelto por esta propiedad no afectará a los Width o Height del control.So, adjusting the Width or Height properties of the Size returned from this property will not affect the Width or Height of the control. Para ajustar el Width o Height del control, debe establecer la propiedad Width o Height del control, o bien establecer la propiedad Size con un nuevo Size.To adjust the Width or Height of the control, you must set the control's Width or Height property, or set the Size property with a new Size.

Nota

Para mantener un mejor rendimiento, no establezca el Size de un control en su constructor.To maintain better performance, do not set the Size of a control in its constructor. El método preferido es invalidar la propiedad DefaultSize.The preferred method is to override the DefaultSize property.

Nota

En los sistemas Windows Server 2003, el tamaño de un Form está restringido por el ancho máximo en píxeles y el alto del monitor.On Windows Server 2003 systems, the size of a Form is restricted by the maximum pixel width and height of the monitor.

Se aplica a

Consulte también: