惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog RSS Feed
J
Java Code Geeks
C
Check Point Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Google DeepMind News
Google DeepMind News
阮一峰的网络日志
阮一峰的网络日志
Engineering at Meta
Engineering at Meta
Blog — PlanetScale
Blog — PlanetScale
D
Docker
H
Hackread – Cybersecurity News, Data Breaches, AI and More
月光博客
月光博客
I
InfoQ
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
A
About on SuperTechFans
L
LangChain Blog
腾讯CDC
Y
Y Combinator Blog
MongoDB | Blog
MongoDB | Blog
Vercel News
Vercel News
MyScale Blog
MyScale Blog
博客园 - Franky
IT之家
IT之家
博客园_首页

博客园 - Louis.Lu.Sz

在C#中,如果声明字段时不加关键字volatile,会影响多线程环境中对该字段的访问吗? Win10, Win11 Ping不通 FastReport使用笔记 Windows窗体控件库的小秘密 在windows桌面显示IP等信息的小工具分享 oracle,根据查询结果结构创建新表 Oracle多表关联如何更新多个字段 我想实现一个通用的配置读写类 【转】Android程序右上角不显示3个点的菜单 Visual studio项目调试时提示“ 你正在调试XXXX的发布版本。” 【原】记录一下第一次使用Python简单处理Excel 【原创】分享一种WPF列表数据的分页打印方案 [原创] 分享一种Asp.NetMVC WebApi作为后端技术结合Vue前端框架开发时开发环境的优雅配置方案 [转]Errors while building APK. You can find the errors in the 'Messages' view.解决办法 [转]oracle数据库转mysql数据库 SaveFileDialog下载模板文件 算法:把一个数字拆分成指定数字的和,允许数字个数为0和重复 WPF简单实现可以左右滑动的CheckBox复选框,样式模仿的微信 WPF里借助附加属性让DataGrid显示行号
[原] c# winform controls 查找指定类型子控件的扩展方法
Louis.Lu.Sz · 2020-08-12 · via 博客园 - Louis.Lu.Sz
//调用
this.Controls.Find<Button>(true).ForEach((btn) => { btn.Enabled = false; });


//定义
public static class FormControlExtensions
    {
        /// <summary>
        /// 获得指定类型的孩子控件
        /// </summary>
        /// <typeparam name="TChild">子控件类型</typeparam>
        /// <param name="controlCollection"></param>
        /// <param name="searchAllChildren">如果搜索所有子控件,则为 true;否则为 false。默认为false。</param>
        /// <returns></returns>
        public static List<TChild> Find<TChild>(this Control.ControlCollection controlCollection, bool searchAllChildren = false) 
            where TChild : Control
        {
            var children = new List<TChild>();
            _Find(controlCollection, ref children, searchAllChildren);
            return children;
        }

        /// <summary>
        /// 查询指定类型的子控件(支持递归)
        /// </summary>
        /// <typeparam name="TChild">子控件类型</typeparam>
        /// <param name="controlCollection"></param>
        /// <param name="children"></param>
        /// <param name="searchAllChildren">如果搜索所有子控件,则为 true;否则为 false。默认为false。</param>
        private static void _Find<TChild>(Control.ControlCollection controlCollection, ref List<TChild> children, bool searchAllChildren = false) 
            where TChild : Control
        {
            foreach (Control control in controlCollection)
            {
                if (control is TChild)
                {
                    children.Add((TChild)control);
                }

                if (control.Controls.Count > 0 && searchAllChildren)
                {
                    _Find(control.Controls, ref children, searchAllChildren);
                }
            }
        }
    }