RadioButton: the Click event was raised unproperly

Control :RadioButton
Description: the RadioButton's Click event was raised even the Checked
property is changed Programmatically in form's constructor/OnLoad event handler.

I have found some document that says, the Click event won't be fired when programmatically changing the Checked property of a radio button.

But actually, if you put a 'radiobutton1.Check = true;' in the constructor of the form, or even in the Form.OnLoad event handler, the Click event will be fired.

So is there any way to identify if it is the user that is choosing this item, not a programmatical changing of the Checked property

(You know i dont like to monitor MouseDown, MouseUp, KeyDown and other tens of events to achieve it)


----

Step 1. Create a new C# Windows Form project.
Step 2. Add some radio buttons.
Step 3. Attach a event handler to one of the radio buttons. Write down sth just like MessageBox.Show("hi") in it.
Step 4. Add a 'radioButton3.Checked = true' immediately after the  'InitializeComponent()' in the constructor.

Run the program and you will see the 'Hi' messagebox was showed even if you never did anything.


Answer this question

RadioButton: the Click event was raised unproperly

  • Alex2003

    Hi,

    Yes this is the behavior even in the late VB6. The click event is being called whenever the state of the radiobutton has been changed. If you want just to catch whenever the user clicks the control, then the proper event would be MouseClick instead of just click. I don't know if its available in VS2003 but it is in VS2005...

     

     

    cheers,

    Paul June A. Domag



  • ColinMcF

    Thank you for your advice.

    Maybe that is just what i am looking for, but it's not available in VS2003/.Net Framework 1.x.
    And from the name 'MouseClick', i would doubt it if it can only catch the mouse action. If the user use a keyboard to select the radiobutton, that event wont be raised, right

  • uchimoto

    Hi,

    So sad its not available in VS2003. Yes it doesn't fire even on keyboard inputs. It strictly fires only when you click it with a mouse.

     

     

    cheers,

    Paul June A. Domag



  • RadioButton: the Click event was raised unproperly