How to: Set the Background of a Windows Forms Panel


A Windows Forms Panel control can display both a background color and a background image. The BackColor property sets the background color for the contained controls, such as labels and radio buttons. If the BackgroundImage property is not set, the BackColor selection will fill the entire panel. If the BackgroundImage property is set, the image will be displayed behind the contained controls.

To set the background programmatically

  1. Set the panel's BackColor property to a value of type System.Drawing.Color.

    panel1.BackColor = Color.AliceBlue;  
  2. Set the panel's BackgroundImage property using the FromFile method of the System.Drawing.Image class.

    // 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  
       + @"\Image.gif");  

Panel Control
Panel Control Overview