Files
docs-desktop/dotnet-desktop-guide/framework/winforms/controls/how-to-set-the-background-of-a-windows-forms-panel.md
T
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

3.0 KiB

title, description, ms.date, dev_langs, helpviewer_keywords, ms.assetid
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
csharp
vb
cpp
background colors [Windows Forms], Windows Forms Panel controls
background images [Windows Forms], Windows Forms Panel controls
Panel control [Windows Forms], background
colors [Windows Forms], Windows Forms Panel controls
096cbd8d-45cc-47b8-b1ef-a27f60ea8be0

How to: Set the Background of a Windows Forms Panel

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.

To set the background programmatically

  1. 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;  
    
  2. 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"));  
    

See also