【问题标题】:get all control names of a form in another form以另一种形式获取一个窗体的所有控件名称
【发布时间】:2011-10-07 14:45:12
【问题描述】:

我有两个表单,分别称为 Customers 和 CustomerControlList 在客户表单中,我有 DevExpress 布局控件,如 TabbedControlGroup、LayoutControlGroup、LayoutItem,在这些 LayoutItems 中,我使用任何控件,如 TextEdit、ComboEdit 等...

我想在 CustomerControlList 中获取所有控件名称,即 TextEdit 等... 那我该怎么做呢?我无法遍历这些布局控件...

例如:我得到表单的实例并循环

frmCustomer fc= new frmCustomer();

foreach(Control c in fc.Controls)
{

}

这不起作用,只有 Windows.Forms.Collection 出现,所以它作为控制计数为零。

还有可能以另一种形式获得动态创建的控件名称吗? 如果有,该怎么做?

谢谢!

【问题讨论】:

    标签: devexpress loops nested-loops


    【解决方案1】:

    这对我有用(这几乎是我的代码的直接翻录):

    TextEdit devXtextControl;
    
    foreach (Control control in this.Controls[0].Controls)
    {
        if ((devXtextControl = control as TextEdit) != null)
        {
            // do something with devXtextControl
            Messagebox.Show(devXtextControl.Name);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-22
      • 2021-03-15
      相关资源
      最近更新 更多