首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >LINQ如何递归子控件

LINQ如何递归子控件

作者头像
跟着阿笨一起玩NET
发布于 2018-09-19 15:15:32
发布于 2018-09-19 15:15:32
1.1K0
举报
代码语言:javascript
复制
private void SetTextReadOnly(Control ctr, bool blReadOnly)
        {
            ctr.Controls.Cast<Control>().Select(s => s).ToList<Control>().ForEach(s =>
                {
                    if (s.GetType() == typeof(TextBox))
                        ((TextBox)s).ReadOnly = blReadOnly;

                    if (s.HasChildren)
                    {
                        SetTextReadOnly(s, blReadOnly);
                    }
                });

            //foreach (Control c in ctr.Controls)
            //{
            //    if (c.GetType() == typeof(TextBox))
            //    {
            //        ((TextBox)c).ReadOnly = true;
            //    }
            //    if (c.HasChildren)
            //    {
            //        SetTextReadOnly(c, blReadOnly);
            //    }
            //}
        }
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2014-08-07 ,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档