Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows C#窗体的主显示设置_C#_Css_.net_Forms - Fatal编程技术网

Windows C#窗体的主显示设置

Windows C#窗体的主显示设置,c#,css,.net,forms,C#,Css,.net,Forms,我正在使用WindowsC#forms、.NET3.5开发一个应用程序 应用程序包含用于接收用户输入、显示报告等的不同表单 在开发这些表单时,我必须在表单之间切换,以确保它们的外观(例如字体大小、表单大小)是一致的。我通过编辑表单属性来实现这一点 我的问题是,是否可以有一个主样式表(如CSS)来控制所有表单的属性?或者如何做到这一点 谢谢。没有类似CSS的方法,但您可以编写一个方法,枚举表单上的所有控件并对其进行样式设置 StyleIt<Label>(this, lbl =>

我正在使用WindowsC#forms、.NET3.5开发一个应用程序 应用程序包含用于接收用户输入、显示报告等的不同表单

在开发这些表单时,我必须在表单之间切换,以确保它们的外观(例如字体大小、表单大小)是一致的。我通过编辑表单属性来实现这一点

我的问题是,是否可以有一个主样式表(如CSS)来控制所有表单的属性?或者如何做到这一点


谢谢。

没有类似CSS的方法,但您可以编写一个方法,枚举表单上的所有控件并对其进行样式设置

StyleIt<Label>(this, lbl => { lbl.ForeColor = Color.Red; });
StyleIt(这个,lbl=>{lbl.ForeColor=Color.Red;});

void StyleIt(表格f,动作)
{
Func allControls=null;
allControls=root=>新控件[]{root}
.Concat(root.Controls.Cast())
.SelectMany(c=>allControls(c));
allControls(f).OfType().ToList()
.ForEach(tb=>action(tb));
}
void StyleIt<T>(Form f, Action<T> action)
{
    Func<Control, IEnumerable<Control>> allControls = null;
    allControls = root => new Control[] { root }
                          .Concat(root.Controls.Cast<Control>()
                                               .SelectMany(c => allControls(c)));

    allControls(f).OfType<T>().ToList()
                  .ForEach(tb => action(tb));
}