Cómo: Establecer el fondo de un control Panel de formularios Windows Forms

Actualización: noviembre 2007

Un control Panel de un formulario Windows Forms puede mostrar tanto un color como una imagen de fondo. La propiedad BackColor establece el color de fondo para los controles que contiene, como, por ejemplo, etiquetas y botones de opción. Si la propiedad BackgroundImage no está establecida, la selección BackColor llenará todo el panel. Si la propiedad BackgroundImage está establecida, la imagen se mostrará detrás de los controles contenidos.

Para establecer el fondo mediante programación

  1. Establezca la propiedad BackColor del panel en un valor de tipo System.Drawing.Color.

    Panel1.BackColor = Color.AliceBlue
    
    panel1.BackColor = Color.AliceBlue;
    
    panel1->BackColor = Color::AliceBlue;
    
  2. Establezca la propiedad BackgroundImage del panel mediante el método FromFile de la clase System.Drawing.Image.

    ' You should replace the bolded image 
    ' in the sample below with an image of your own choosing.
    Panel1.BackgroundImage = Image.FromFile _
        (System.Environment.GetFolderPath _
        (System.Environment.SpecialFolder.Personal) _
        & "\Image.gif")
    
    // You should replace the bolded image 
    // in the sample below with an image of your own choosing.
    // Note the escape character used (@) when specifying the path.
    panel1.BackgroundImage = Image.FromFile
       (System.Environment.GetFolderPath
       (System.Environment.SpecialFolder.Personal)
       + @"\Image.gif");
    
    // You should replace the bolded image 
    // in the sample below with an image of your own choosing.
    panel1->BackgroundImage = Image::FromFile(String::Concat(
       System::Environment::GetFolderPath
       (System::Environment::SpecialFolder::Personal),
       "\\Image.gif"));
    

Vea también

Referencia

Información general del control Panel (formularios Windows Forms)

BackColor

BackgroundImage

Otros recursos

Control Panel (Windows Forms)