【问题标题】:find control by name with linq使用 linq 按名称查找控件
【发布时间】:2011-05-25 14:52:43
【问题描述】:

大家好,是否可以通过 Linq 按名称查找控件?

我可以通过 for each 遍历彻底的 contorl 集合

foreach (RibbonTab t in testRibbon.CommandTabs)
                    {
                        if (t.Name == tab.Name)
                        {
                            blnFound= true;

                        }
                    }

这个想法是为了节省内存。 我动态创建 Telerik 功能区选项卡,我想查看该选项卡是否存在然后不创建它,我还想检查功能区栏是否具有特定的 RadRibbonBarGroup 和 RadButtonElement,其名称与功能区选项卡相同,因此我不会重复。

对不起,如果我有点复杂。

【问题讨论】:

    标签: c# winforms linq telerik ribbon


    【解决方案1】:
    bool found = testRibbon.CommandTabs.Cast<RibbonTab>().Any(t => t.name == tab.Name);
    

    【讨论】:

      【解决方案2】:

      是的,这可以通过 Linq-to-WindowsForms 实现。请参阅以下文章:

      http://www.codeproject.com/KB/linq/LinqToTree.aspx#linqforms

      您可以找到所有具有给定名称的控件,如下所示:

      var namedControls= this.Descendants()
                             .Where(ctrl => ctrl.Name="NameToFind");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-23
        • 2014-03-21
        相关资源
        最近更新 更多