共用方式為


如何:設定 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. 使用 System.Drawing.Image 類別的 FromFile 方法設定面板的 BackgroundImage 屬性。

    ' 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"));  
    

另請參閱