C# Button button = (Button)sender;

来源:百度知道 编辑:UC知道 时间:2024/06/25 12:00:13
这是什么

这个一般是用现按钮事件中的
sender就是你点的那个按钮对像,
这话的意思是将sender强制转换成Button类型

不过最好这样写
Button button=sender as Button;
之后用
if(button!=null)
{
//to do
}

定义一个Button变量,把sender这个对象强制转换成Button类型赋给button

sender表示产生事件的对象,比如你点击一个按钮,sender就表示这个按钮.这里你就可以用button.Enabled等东西了。