遍历WinForm中的所有控件,只执行一次以下语句是不行的 foreach (Control ctl in this.Controls) { } 这样只能遍历到第一层控件,子控件是遍历不到的,要想遍历所有存在的控件,需要递归解决 //伪代码如下 void EnumControls(Control container) { foreach(Control c in container.Controls) { //c is the child control here EnumControls(c)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace xiaojian2 { public partial class Form1 : Form { public F
1.常用调用方法 public partial class UCRights : UserControl { private readonly int LOCATIONY; private DataTable MENU = new DataTable(); private BLL.User oUser = new HRPOWER.BLL.User(); public UCRights() { InitializeComponent(); LOCATIONY = panRightMenu_Top.
//循环整个form上的控件 foreach (Control c in this.Controls) { //看看是不是checkbox if (c is CheckBox) { //将找到的control转化成checkbox CheckBox ck = c as CheckBox; //判断是否选中 if (ck.Checked) { //该复选框被选择 } }else if ... }