<p>I have a radio button on my Windows Form. How can I determine if the CheckChanged event occurred due to a user clicking or selecting the radio button vs programatically setting the event with </p>

<pre><code>this.radioButtonAdd.Checked = true;
</code></pre>

<p>I would like some code to take a different action depending on if the user clicked the button or I raised the event myself.</p>

<p>Or maybe the better question is how do I handle the event when a user clicks vs when the state is changed in my code.</p>

If there is a built-in method, then I am not aware of it.
One way to handle it is by setting a global flag while the code is making changes that tells the event handler.  For example, the code making the changes could look something like the following:
```
```
savedFlag = modifyingProgrammatically;
modifyingProgrammatically = true;
this.radioButtonAdd.Checked = true;
modifingProgrammatically = savedFlag;
```
```
Within your event handler:
```
```
if(modifyingProgramatically) {
    // The event was raised by an assignment within the code.
} else {
    // The event was raised by a user action.
}
```
```