借助于反射,可获取当前窗体中的所有控件,根据需要设置它们的属性。
Font defaultFont = new System.Drawing.Font("Microsoft Sans Serif", 8.25F); //查找所有的控件,设置为同样的字体 IterateControls(this.Controls, typeof(Foundation.WinUI.Misc.Label)); foreach (Control ctrl in grids) { ctrl.Font = defaultFont; } grids = new List<Control>(); IterateControls(this.Controls, typeof(Foundation.WinUI.Misc.TabControl)); foreach (Control ctrl in grids) { foreach (UltraTab tab in (ctrl as Foundation.WinUI.Misc.TabControl).Tabs) { tab.Appearance.FontData.Name = defaultFont.Name; tab.Appearance.FontData.SizeInPoints = defaultFont.SizeInPoints; } } grids = new List<Control>(); IterateControls(this.Controls, typeof(Foundation.WinUI.Editors.CheckBoxEditor)); foreach (Control ctrl in grids) { ctrl.Font = defaultFont; }
获取指定类型控件的方法:
private void IterateControls(Control.ControlCollection controls, Type type) { foreach (Control child in controls) { if (child.GetType() == type) grids.Add(child); if (child.HasChildren) IterateControls(child.Controls, type); } }
代码来自stackoverflow。
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
时间: 2024-10-14 11:12:10