linq 查找控件

来源:互联网 发布:南方和北方的区别知乎 编辑:程序博客网 时间:2024/05/17 03:40

查找类型为Panel的控件

var control = from tempcontrol in this.ActiveMdiChild.Controls.OfType<Panel>().AsQueryable() where tempcontrol.Name == "panel1" select tempcontrol;


var control1 = from tempcontrol1 in control.ElementAt<Panel>(0).Controls.OfType<GroupBox>().AsQueryable() where tempcontrol1.Name == "groupBox1" select tempcontrol1;


var control2 = from tempcontrol2 in control1.ElementAt<GroupBox>(0).Controls.OfType<TextBox>().AsQueryable() where tempcontrol2.Name == "fileNameTextBox" select tempcontrol2;

给控件设置值

control2.ElementAt<TextBox>(0).Text = openFileDialog.FileName;

原创粉丝点击