Versión imprimible       Enviar     
Evaluar y enviar comentarios
MSDN
MSDN Library
 BackgroundImage (Propiedad)
Contraer todo/Expandir todo Contraer todo
Esta página es específica de
Microsoft Visual Studio 2005/.NET Framework 2.0

Hay además otras versiones disponibles para:
Control.BackgroundImage (Propiedad)
Obtiene o establece la imagen de fondo que se muestra en el control.

Espacio de nombres: System.Windows.Forms
Ensamblado: System.Windows.Forms (en system.windows.forms.dll)

Visual Basic (Declaración)
<LocalizableAttribute(True)> _
Public Overridable Property BackgroundImage As Image
Visual Basic (Uso)
Dim instance As Control
Dim value As Image

value = instance.BackgroundImage

instance.BackgroundImage = value
C#
[LocalizableAttribute(true)] 
public virtual Image BackgroundImage { get; set; }
C++
[LocalizableAttribute(true)] 
public:
virtual property Image^ BackgroundImage {
    Image^ get ();
    void set (Image^ value);
}
J#
/** @property */
public Image get_BackgroundImage ()

/** @property */
public void set_BackgroundImage (Image value)
JScript
public function get BackgroundImage () : Image

public function set BackgroundImage (value : Image)
XAML
No aplicable.

Valor de propiedad

Image que representa la imagen que se va a mostrar en el fondo del control.
  • Utilice la propiedad BackgroundImage para colocar una imagen gráfica en un control.

NotaNota:

Los controles de formularios Windows Forms no admiten imágenes de fondo con colores translúcidos o transparentes como imágenes de fondo.

Esta propiedad no es compatible en controles secundarios cuya propiedad RightToLeftLayout es true.

Notas para los herederos: Cuando se reemplaza la propiedad BackgroundImage en una clase derivada, hay que utilizar la propiedad BackgroundImage de la clase base para extender la implementación base. Si no, deberá proporcionarse toda la implementación. No es necesario reemplazar ambos descriptores de acceso get y set de la propiedad BackgroundImage; se puede reemplazar sólo uno, si es necesario.

En el ejemplo de código siguiente se agrega un control Button a un formulario y se establecen algunas de sus propiedades comunes. En el ejemplo se fija el botón en la esquina inferior derecha del formulario para que mantenga su posición relativa cuando se cambie el tamaño del formulario. A continuación se establece la propiedad BackgroundImage y se cambia el tamaño del botón para que tenga el mismo tamaño que Image. En el ejemplo se establece después la propiedad TabStop en true y se establece la propiedad TabIndex. Por último, se agrega un controlador de eventos para controlar el evento Click del botón. En este ejemplo es necesario que se disponga de un ImageList denominado imageList1.

Visual Basic
' 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
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);
}
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 = 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 );
   }
J#
// 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.set_Anchor(AnchorStyles.Bottom | AnchorStyles.Right);
    // Assign a background image.
    button1.set_BackgroundImage(imageList1.get_Images().get_Item(0));
    // Specify the layout style of the background image. Tile is the 
    // default.
    button1.set_BackgroundImageLayout(ImageLayout.Center);
    // Make the button the same size as the image.
    button1.set_Size(button1.get_BackgroundImage().get_Size());
    // Set the button's TabIndex and TabStop properties.
    button1.set_TabIndex(1);
    button1.set_TabStop(true);
    // Add a delegate to handle the Click event.
    button1.add_Click(new System.EventHandler(this.button1_Click));
    // Add the button to the form.
    this.get_Controls().Add(button1);
} //AddMyButton

Windows 98, Windows 2000 Service Pack 4, Windows CE, Windows Millennium, Windows Mobile para Pocket PC, Windows Mobile para Smartphone, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter

Microsoft .NET Framework 3.0 es compatible con Windows Vista, Microsoft Windows XP SP2 y Windows Server 2003 SP1.

.NET Framework

Compatible con: 3.0, 2.0, 1.1, 1.0
© 2009 Microsoft Corporation. Reservados todos los derechos. Términos de uso | Marcas Registradas | Privacidad
Page view tracker