日期:2014-05-19  浏览次数:20867 次

按钮的单击问题.....
想根据按钮是否按下来来做个判断
就是按钮按下时,定义一个bool值=1,没按=0
该怎么实现?

------解决方案--------------------
private bool bPush = false;
private void button1_Click(object sender, EventArgs e)
{
bPush = !bPush;
if(bPush)
button1.text = "1 ";
else
button1.text = "0 ";
}
------解决方案--------------------
bool 类似enum,只有True,False 0和1纯属瞎扯,添加mouse事件可以改变bool的值

private bool IsPressed = false;
private void buttou_MouseUp(object sender, MouseEventArgs e)
{
IsPressed = false;
this.Text = IsPressed.ToString();
}

private void button_MouseDown(object sender, MouseEventArgs e)
{
IsPressed = true;
this.Text = IsPressed.ToString();
}