关于动态获取控件实例
我有3个字符串变量,分别代表窗体名称、控件类型、控件名称
如何动态获取控件实例,实现如下功能
窗体名称.控件名称.Enabled = false;
即
this.button1.Enabled = false;
------解决方案--------------------直接赋值即可啊
c.BackColor = Color.Red;
c.Enabled = false;
////
string[,] array2D = new string[,] { { "Button ", "button1 " }, { "System.Windows.Forms.ComboBox ", "comboBox1 " }, { "System.Windows.Forms.TextBox ", "textBox1 " }, { "ToolStripMenuItem ", "这项实验ToolStripMenuItem " } };
for (int indexRow = 0; indexRow < array2D.GetLength(0); indexRow++)
{
foreach (Control c in this.Controls)
{
if ((c.GetType().ToString()==s) && c.Name == ss)
c.BackColor = Color.Red;
c.Enabled = false;
}
}
}