2
votes

I createbtn1_MouseDown Event.

  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;     
    }

Is that possible ?

3
Why are you comparing a boolean to true?lc.
@lc very simple - checked is nullable boolean so you have to compare to true :)Adam Bilinski
@AdamBilinski: This seems to be WinForms, where it is not a nullable bool, but a normal bool.O. R. Mapper
@AdamBilinski Really? Last I checked RadioButton.Checked was a System.Booleanlc.
@lc of course you are right I was thinking about CheckBox :)Adam Bilinski

3 Answers

3
votes

inside r1_checkeChanged add:

btn1.MouseDown -=btn1_MouseDown;
0
votes

You can remove the event:

btn1.MouseDown -= btn1_MouseDown

Of course don't forget to add it back again when you need it.


However, instead of doing that I would change your event handler's code to check the state of the radio button:

private void btn1_MouseDown(object sender, MouseEventArgs e)
{
    if (!r1.Checked)
        btn1.BackgroundImage = Properties.Resources.click;
}
0
votes

1st option can be to remove the event at radio button check_change event like this:

btn1.MouseDown -=btn1_MouseDow;

but i dont prefer this way.
Second is to add a flag at start of this event and check whether to execute the event or not like this:

bool flag;

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