有时,问了项目的需求,与界面的好看,我们往往会使窗体用不同的页面颜色,供用户体验,当用户选中不同的颜色,那么窗体里面空间的字体颜色也得跟着变,那么我们应该如何:怎样改动groupbox空间里面的颜色:
下面提供代码:
public static void ChangePanel(System.Windows.Forms.Control PanelData)
{
if (PanelData.Controls == null) return;
Color tcolor;
try
{
//获取当前的颜色
tcolor = ColorTranslator.FromHtml(GlobalParams.ResManager.GetObject("ToolBarForeColor").ToString());
}
catch
{
return;
}
for (int i = 0; i < PanelData.Controls.Count; i++)
{
//获取用户空间类型,是显示不同的颜色
PanelData.Controls[i].ForeColor = tcolor;
if (PanelData.Controls[i].GetType() == typeof(System.Windows.Forms.Label))
{
((System.Windows.Forms.Label)PanelData.Controls[i]).ForeColor = tcolor;
}
else if (PanelData.Controls[i].GetType() == typeof(System.Windows.Forms.CheckBox))
{
((System.Windows.Forms.CheckBox)PanelData.Controls[i]).ForeColor = tcolor;
}
else if (PanelData.Controls[i].GetType() == typeof(System.Windows.Forms.CheckedListBox))
{
((System.Windows.Forms.CheckedListBox)PanelData.Controls[i]).ForeColor = tcolor;
}
}
}