- 例如:我们知道控件名为"textbox1"需要对textbox1进行赋值;通常我们只要textbox1.text = "你好";即可 此处我们是通过"textbox1"获得控件textbox1(很绕口,我找资料都不知道该怎么搜)
//<summary> /// 在winform中查找控件 ///</summary> ///<param ></param> ///<param ></param> ///<returns></returns> private Control findControl(Control control, string controlName) { Control c1; foreach (Control c in control.Controls) { if (c.Name == controlName) { return c; } else if (c.Controls.Count > 0) { c1 = findControl(c, controlName); if (c1 != null) { return c1; } } } return null; }
调用方法
findControl(this, CurrentCom).Text = "你好";