如何枚举 winform 中所有的组件? foreach(Control c in this.Controls) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是不是得到继承Control的所有控件:Type t = typeof(System.Windows.Forms.Control);Type[] types = t.Assembly.GetTypes();for (int i = 0; i < types.Length; i++) { if (types[i].IsSubclassOf(t)) { Console.WriteLine(types[i]); }} 不是这个意思,我是说,得到窗体中等所有组件: Component继承 Component 的所有组件,如 menuitem,FileSystemWatcher,Timer 等. System.Windows.Forms.Form也许没有这样的东西不能确定,请比较清楚的人作答 所有的Control都在属性Controls里;所有的Component都在字段components里;所以这样就可以了:ArrayList list = new ArrayList();getControls(this, list);for (int i = 0; i < components.Components.Count; i++) { list.Add(components.Components[i]);}static void getControls(Control container, ArrayList list) {for(int i = 0; i < container.Controls.Count; i++) { list.Add(container.Controls[i]);}for(int i = 0; i < container.Controls.Count; i++) { Control c = container.Controls[i]; if (c.Controls.Count > 0) { getControls(c, list); }}}这样就可以得到Form所有定义的Component了。 所有的Control都在属性Controls里;.............前提是已添加到Controls所有的Component都在字段components里;.........前提是已添加到Components 页面加载,图片显示的是老图片 请教BCB怎么调用c#的COM(调用的时候提示抽象类.....) 怎么实现淘宝首页的图片轮换效果 我知道一台机器的域名为shipin.zhengsheng.com.cn,机器名为shipin,域名服务器的ip用户名密码我都知道 打开指定EXCEL文件 c#中,使用框架后,session立即过期是何原因? 关于combobox的问题,请高手指点一下! 高分:过滤datagrid中的行 WebBrower问题 Wpf 动画 求C#的注册码生成的代码 如何让程序已启动时就最小化,显示在任务栏上!!
Type t = typeof(System.Windows.Forms.Control);
Type[] types = t.Assembly.GetTypes();
for (int i = 0; i < types.Length; i++) {
if (types[i].IsSubclassOf(t)) {
Console.WriteLine(types[i]);
}
}
继承 Component 的所有组件,如 menuitem,FileSystemWatcher,Timer 等.
所有的Component都在字段components里;
所以这样就可以了:
ArrayList list = new ArrayList();
getControls(this, list);
for (int i = 0; i < components.Components.Count; i++) {
list.Add(components.Components[i]);
}static void getControls(Control container, ArrayList list) {
for(int i = 0; i < container.Controls.Count; i++) {
list.Add(container.Controls[i]);
}
for(int i = 0; i < container.Controls.Count; i++) {
Control c = container.Controls[i];
if (c.Controls.Count > 0) {
getControls(c, list);
}
}
}
这样就可以得到Form所有定义的Component了。
所有的Component都在字段components里;.........前提是已添加到Components