方法一:
那么第三次按下时呢,执行哪个事件?
private void button1_Click(object sender, System.EventArgs e)
{
int clickTimes; //按下du次数
//获取按zhi下次数
object tag = this.button1.Tag;
if (tag == null)
{
clickTimes = 0;
}
else
{
clickTimes = Convert.ToInt32(tag);
}
//增加并记录按下次数
this.button1.Tag = ++clickTimes;
if ((clickTimes%2) == 1)
{
//执行你的事dao情1
MessageBox.Show(“奇数次”);
}
else
{
//执行你的事情2
MessageBox.Show(“偶数次”);
}
}
方法二:
Button button=new Button();
button.Click+= btn_Click1;
bool bStatus=false;//标记按钮当前状态,false表示按钮目前显示的是扫描,true显示的是暂停
void btn_Click1(object o,EventArgs e)
{
bStatus=!bStatus;//状态切换
if(bStatus == false)
{
button.Text=“扫描”;
//做你想做的事情,比如扫面文件
}else
{
button.Text=“暂停”;
//做你想做的事情,比如暂停文件按扫描
}
}
方法三:
//初始bai化
Button button=new Button();
button.Click+= btn_Click1;
void btn_Click1(object o,EventArgs e) {
button.Click-=btn_Click1;
button.Click+=btn_Click2;
//做其他du事zhi。dao
}
void btn_Click2(object o,EventArgs e) {
button.Click-=btn_Click2;
button.Click+=btn_Click1;
//做其他事。
}
方法四:
void btndown()
{
static bool f=true;
if(f)
{
f=false;
//xxxxx
}
else
{
f=true;
//yyyyy
}
}