C# 使用linq按名称查找控件
大家好,可以通过Linq找到一个名为controll的控件吗 我可以通过为每个对象迭代thorught contorl集合C# 使用linq按名称查找控件,c#,winforms,linq,telerik,ribbon,C#,Winforms,Linq,Telerik,Ribbon,大家好,可以通过Linq找到一个名为controll的控件吗 我可以通过为每个对象迭代thorught contorl集合 foreach (RibbonTab t in testRibbon.CommandTabs) { if (t.Name == tab.Name) { blnFound= true;
foreach (RibbonTab t in testRibbon.CommandTabs)
{
if (t.Name == tab.Name)
{
blnFound= true;
}
}
这个想法是为了节省内存。
我动态创建telerik ribbon选项卡,我想看看选项卡是否存在,然后不创建它。我还想检查ribbonbar是否有特定的RadRibbonBarGroup和RadButtonneElement,其名称与ribbontab相同,因此我不会重复
对不起,我有点复杂了 boolfound=testRibbon.CommandTabs.Cast().Any(t=>t.name==tab.name);
bool found = testRibbon.CommandTabs.Cast<RibbonTab>().Any(t => t.name == tab.Name);
是的,这可以通过Linq到WindowsForms实现。见以下文章:
您可以找到具有给定名称的所有控件,如下所示:
var namedControls= this.Descendants()
.Where(ctrl => ctrl.Name="NameToFind");