在一个鼠标Click事件中
viod mClick(object sender, EventArgs e){}如果发送人是 button类型的话,可以
((button)sender).Text="adsf";
这样改变内容.但是如果是未知类型呢?而该类型也有Text、Name等属性有没有适合任意类型的转换可以直接给Text、Name等属性进行赋值的方法?
viod mClick(object sender, EventArgs e){}如果发送人是 button类型的话,可以
((button)sender).Text="adsf";
这样改变内容.但是如果是未知类型呢?而该类型也有Text、Name等属性有没有适合任意类型的转换可以直接给Text、Name等属性进行赋值的方法?
先判断类型
viod mClick(object sender, EventArgs e){
if(sender is Control)
{
(sender as Control).Text="adsf"
}
}
--------------------------总归是个控件吧,控件都是从Control类派生的,转换为Control就是了。
sender.GetType().Name 返回的是 Button