2

我创建btn1_MouseDown事件。

  private void btn1_MouseDown(object sender, MouseEventArgs e)
    {
        btn1.BackgroundImage = Properties.Resources.click;
    }

I want to disable that btn1_MouseDownt Event behind this RadioButton when it checked. I mean to say when Radiobutton checked then this btn1_MouseDown event should not work.

    private void r1_CheckedChanged(object sender, EventArgs e)
    {

        if (r1.Checked == true)
            clock = 5;

        radioButton2.Enabled = false;
        radioButton3.Enabled = false;
        radioButton4.Enabled = false;     
    }

那可能吗 ?

4

3 回答 3

3

里面r1_checkeChanged添加:

btn1.MouseDown -=btn1_MouseDown;
于 2013-01-19T14:41:39.623 回答
0

您可以删除事件:

btn1.MouseDown -= btn1_MouseDown

当然不要忘记在需要时再次添加它。


但是,我不会这样做,而是更改您的事件处理程序的代码以检查单选按钮的状态:

private void btn1_MouseDown(object sender, MouseEventArgs e)
{
    if (!r1.Checked)
        btn1.BackgroundImage = Properties.Resources.click;
}
于 2013-01-19T14:43:21.723 回答
0

1st option可以在单选按钮 check_change 事件中删除事件,如下所示:

btn1.MouseDown -=btn1_MouseDow;

但我不喜欢这种方式。
Second就是在这个事件开始时添加一个标志并检查是否执行该事件,如下所示:

bool flag;

private void btn1_MouseDown(object sender, MouseEventArgs e)
{
    if (flag) return;
    btn1.BackgroundImage = Properties.Resources.click;
}
于 2013-01-19T14:45:34.690 回答