利用控件名(字符串)调用控件的方法:

string currentButtonName = "buttonLinked";

//第1种
Button temButton = (Button)this.GetType().GetField
(currentButtonName, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.IgnoreCase).GetValue(this);
//第2种 Control c
= (Control)System.Activator.CreateInstance(Type.GetType
("System.Windows.Forms. " +currentButtonName+ ", System.Windows.Forms, version=1.0.5000.0, culture=neutral, publickeytoken=b77a5c561934e089 "));

 

//另外的一种获取方式
string
txt = rdbutton.Text;//获取控件字符 //在枚举数据类型中,调用Enum.Parse方法可以根据提供的枚举值的名字转换为枚举值 //并将转换的枚举值赋值给ListBox1.SelectionMode listBox1.SelectionMode = (SelectionMode)Enum.Parse(typeof(SelectionMode), txt);

 

posted @ 2020-02-13 21:05  xiaoxinZard  阅读(402)  评论(0)    收藏  举报