zoukankan      html  css  js  c++  java
  • 设置Form窗体中的控件的属性

    借助于反射,可获取当前窗体中的所有控件,根据需要设置它们的属性。

     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。

     
  • 相关阅读:
    FastDFS 安装与使用
    leecode刷题(18)-- 报数
    时间戳转换日期格式
    嵌入式Linux的FTP服务端软件(stupid-ftpd)
    iMx280A测试声纹
    Linux 版本查询
    Linux下的目录结构
    uboot主Makefile分析
    uboot配置过程详解1
    路由器设置
  • 原文地址:https://www.cnblogs.com/JamesLi2015/p/4651770.html
Copyright © 2011-2022 走看看