title | description | ms.date | dev_langs | helpviewer_keywords | ms.assetid | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Set the Background of a Panel |
Learn how to set the background color and background image of a Windows Forms panel using the Designer. |
03/30/2017 |
|
|
096cbd8d-45cc-47b8-b1ef-a27f60ea8be0 |
A Windows Forms xref:System.Windows.Forms.Panel control can display both a background color and a background image. The xref:System.Windows.Forms.Control.BackColor%2A property sets the background color for the contained controls, such as labels and radio buttons. If the xref:System.Windows.Forms.Control.BackgroundImage%2A property is not set, the xref:System.Windows.Forms.Control.BackColor%2A selection will fill the entire panel. If the xref:System.Windows.Forms.Control.BackgroundImage%2A property is set, the image will be displayed behind the contained controls.
-
Set the panel's xref:System.Windows.Forms.Control.BackColor%2A property to a value of type xref:System.Drawing.Color?displayProperty=nameWithType.
Panel1.BackColor = Color.AliceBlue
panel1.BackColor = Color.AliceBlue;
panel1->BackColor = Color::AliceBlue;
-
Set the panel's xref:System.Windows.Forms.Control.BackgroundImage%2A property using the xref:System.Drawing.Image.FromFile%2A method of the xref:System.Drawing.Image?displayProperty=nameWithType class.
' 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"));
- xref:System.Windows.Forms.Control.BackColor%2A
- xref:System.Windows.Forms.Control.BackgroundImage%2A
- Panel Control
- Panel Control Overview