当前位置:编程学习 > C#/ASP.NET >>

winform如何获取页面的所有的控件.

我指的不是Controls里面递归循环可以找到的那些.
我需要的是,例如鼠标右键菜单这类控件,在页面上是直接放在最下面的那种控件
由于我发现在自动生成的Form1.Designer.cs里面没有这句话.
  this.components = new System.ComponentModel.Container();
所以想要遍历也找不到,请各位指教 --------------------编程问答-------------------- 访问this.components中的组件 --------------------编程问答-------------------- 采用的是DevExpress 控件
发现没有实例化
private System.ComponentModel.IContainer components = null;
就是没有这段
this.components = new System.ComponentModel.Container(); --------------------编程问答-------------------- Dev控件在注册之后如果想实例化的话,是需要引用命名空间的吧 --------------------编程问答-------------------- 放进this.Components中的并非控件  属于组件  
控件直接加入到父控件中的Controls集合  在this.Components中找不到 --------------------编程问答-------------------- 不管用的什么控件。它在生成的时候总是依附于谁加载的。这个时候你在设计代码里面找到 就可以知道要在哪里才能找到你要的东西。 --------------------编程问答--------------------
引用 4 楼 xiaozhi_5638 的回复:
放进this.Components中的并非控件  属于组件  
控件直接加入到父控件中的Controls集合  在this.Components中找不到

我同意的你得说法,但是目前我页面生成的组件没有加入到this.Components,所以这点我很不明白

引用 5 楼 a549013598 的回复:
不管用的什么控件。它在生成的时候总是依附于谁加载的。这个时候你在设计代码里面找到 就可以知道要在哪里才能找到你要的东西。

在没有this.Components的情况下我想知道他是依附谁的,我就是不知道如何获取 --------------------编程问答--------------------             IContainerControl col = this.GetContainerControl();
            Control con = this.GetNextControl(new Button(), true);
            System.Collections.IEnumerator control = this.Controls.GetEnumerator();
            while (control.MoveNext())
            {
                Control ctr = control.Current as Control;
                if (ctr != null)
                    MessageBox.Show(ctr.Text.ToString());
            }

这面的全部控件获取!Groubox 或 tap 里面的嵌套的是自己写算法! --------------------编程问答--------------------
引用 7 楼 burslane 的回复:
            IContainerControl col = this.GetContainerControl();
            Control con = this.GetNextControl(new Button(), true);
            System.Collections.IEnumerator control = this.Controls.GetEnumerator();
            while (control.MoveNext())
            {
                Control ctr = control.Current as Control;
                if (ctr != null)
                    MessageBox.Show(ctr.Text.ToString());
            }

这面的全部控件获取!Groubox 或 tap 里面的嵌套的是自己写算法!

感谢你的回答,但是这个方式我还是获取不到窗体组件的信息,我指的是页面下面的例如Timer这类组件的对象 --------------------编程问答-------------------- 有知道的么谢谢告之
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,