我在我的桌面应用程序中使用MetroFramework并将所有主题颜色设置为默认,同时在父表单中进行更改我想要将所有子表单和控件颜色更新为par主题颜色。
检查设计UI
http://thielj.github.io/MetroFramework
更改主题
var m = new Random();
int next = m.Next(0, 13);
this.Style = (MetroColorStyle)next;
通过操作,主窗体颜色正在改变,但控制器和子窗体样式颜色不会改变。
答案 0 :(得分:5)
hHi Sunil,
Exmple -1 MetroStyleManager中的工具箱添加
示例2(扩展方法)
public static void SetDefaultStyle(this IContainer contr, MetroForm owner, MetroColorStyle style)
{
MetroStyleManager manager = FindManager(contr, owner);
manager.Style = style;
}
public static void SetDefaultTheme(this IContainer contr, MetroForm owner, MetroThemeStyle thme)
{
MetroStyleManager manager = FindManager(contr, owner);
manager.Theme = thme;
}
private static MetroStyleManager FindManager(IContainer contr, MetroForm owner)
{
MetroStyleManager manager = new MetroStyleManager(contr);
foreach (IComponent item in contr.Components)
{
if (((MetroStyleManager)item).Owner == owner)
{
manager = (MetroStyleManager)item;
}
}
return manager;
}
使用:
public frmMain()
{
InitializeComponent();
this.components.SetDefaultStyle(this, MetroColorStyle.Purple);
}
例子 - 3 :如果您想为所有表单设置主题。
第1步:创建新类" MyExtensions.cs"。这是内容:
public static class MyExtensions
{
//What is your style
private const MetroColorStyle FormStyle = MetroColorStyle.Green;
public static void SetStyle(this IContainer container, MetroForm ownerForm)
{
if (container == null)
{
container = new System.ComponentModel.Container();
}
var manager = new MetroFramework.Components.MetroStyleManager(container);
manager.Owner = ownerForm;
container.SetDefaultStyle(ownerForm, FormStyle);
}
public static void SetDefaultStyle(this IContainer contr, MetroForm owner, MetroColorStyle style)
{
MetroStyleManager manager = FindManager(contr, owner);
manager.Style = style;
owner.Style = style;
}
public static void SetDefaultTheme(this IContainer contr, MetroForm owner, MetroThemeStyle thme)
{
MetroStyleManager manager = FindManager(contr, owner);
manager.Theme = thme;
}
private static MetroStyleManager FindManager(IContainer contr, MetroForm owner)
{
MetroStyleManager manager = null;
foreach (IComponent item in contr.Components)
{
if (((MetroStyleManager)item).Owner == owner)
{
manager = (MetroStyleManager)item;
}
}
return manager;
}
}
第2步:在所有表单中,您需要在" Load"中调用劣质方法。方法。
的Form1.cs例外private void Form1_Load(object sender, EventArgs e)
{
this.components.SetStyle(this);
}
答案 1 :(得分:0)
metroStyleManager1.Theme = metroStyleManager1.Theme == MetroThemeStyle.Light ? MetroThemeStyle.Dark : MetroThemeStyle.Light;
this.Theme = metroStyleManager1.Theme;
this.Refresh();
答案 2 :(得分:0)