Compartir a través de


Cómo: Establecer el fondo de un panel de Formularios Windows Forms

Un control de Windows Forms Panel puede mostrar un color de fondo y una imagen de fondo. La BackColor propiedad establece el color de fondo de los controles contenidos, como etiquetas y botones de radio. Si no se establece la BackgroundImage propiedad, la BackColor selección rellenará todo el panel. Si se establece la BackgroundImage propiedad , 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"));
    

Consulte también