Compartir a través de


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

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

Consulte también