如何:设置 Windows 窗体面板的背景
更新:2007 年 11 月
Windows 窗体 Panel 控件既可以显示背景颜色又可以显示背景图像。BackColor 属性为所包含的控件(如标签和单选按钮)设置背景颜色。如果未设置 BackgroundImage 属性,则为 BackColor 选择的颜色将充满整个面板。如果设置了 BackgroundImage 属性,则该图像将显示在所包含的控件的后面。
以编程方式设置背景
将面板的 BackColor 属性设置为 System.Drawing.Color 类型的值。
Panel1.BackColor = Color.AliceBlue
panel1.BackColor = Color.AliceBlue;
panel1->BackColor = Color::AliceBlue;
使用 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"));