如何:設定 Windows Form 面板的背景

Windows Forms Panel 控制項可以同時顯示背景色彩和背景影像。 屬性 BackColor 會設定自主控制項的背景色彩,例如標籤和選項按鈕。 BackgroundImage如果未設定 屬性,選取 BackColor 專案將會填滿整個面板。 BackgroundImage如果已設定 屬性,則會在自主控制項後面顯示影像。

以程式設計方式設定背景

  1. 將面板的 BackColor 屬性設定為 類型的 System.Drawing.Color 值。

    Panel1.BackColor = Color.AliceBlue  
    
    panel1.BackColor = Color.AliceBlue;  
    
    panel1->BackColor = Color::AliceBlue;  
    
  2. 使用 FromFile 類別的 方法設定面板 BackgroundImage 的屬性 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"));  
    

另請參閱