Control.BackgroundImage Propiedad

Definición

Obtiene o establece la imagen de fondo que se muestra en el control.

C#
public virtual System.Drawing.Image BackgroundImage { get; set; }
C#
public virtual System.Drawing.Image? BackgroundImage { get; set; }

Valor de propiedad

Image que representa la imagen que se va a mostrar en el fondo del control.

Ejemplos

En el ejemplo de código siguiente se agrega un Button objeto a un formulario y se establecen algunas de sus propiedades comunes. En el ejemplo se ancla el botón a la esquina inferior derecha del formulario para que mantenga su posición relativa a medida que se cambia el tamaño del formulario. A continuación, establece y BackgroundImage cambia el tamaño del botón al mismo tamaño que .Image A continuación, el ejemplo establece en TabStoptrue y establece la TabIndex propiedad . Por último, agrega un controlador de eventos para controlar el Click evento del botón. En este ejemplo se requiere que tenga un ImageList denominado imageList1.

C#
// 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);
}

Comentarios

  • Utilice la BackgroundImage propiedad para colocar una imagen gráfica en un control.

Nota

Las imágenes con colores transparentes o translúcidos no son compatibles con los controles de Windows Forms como imágenes de fondo.

Esta propiedad no se admite en los controles secundarios cuya RightToLeftLayout propiedad es true.

Notas a los desarrolladores de herederos

Al invalidar la BackgroundImage propiedad en una clase derivada, use la propiedad de BackgroundImage la clase base para ampliar la implementación base. De lo contrario, debe proporcionar toda la implementación. No es necesario invalidar los get descriptores de acceso y set de la BackgroundImage propiedad; solo puede invalidar uno si es necesario.

Se aplica a

Producto Versiones
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Consulte también