tags:

views:

17

answers:

1

Suppose you are using a control such as NumericUpDown which has the value property. and you set the value numericUpDown1.Value = 10; then the .net will fire the event numericaUpDown1ValueChanged(sender, args), also the user can directly set the value of this control and the .Net will fire the same event with the same sender.

to be able to identify whether the event was generated by code or by direct user input, I would usually wrap my assignment as the following:

userDirectlyChangingValue = false;
numericaUpDown1.Value = 10;
userDirectlyChangingValue = true;

then within the numericaUpDown1ValueChanged(sender, args) event I would use userDirectlyChangingValue to identify the way the event was generated and act accordingly.

my question is, is there a better/direct way in the .Net to accomplish this?

Thanks

A: 

No, this is the universally adopted way of doing this. Unsubscribing the event handler and re-subscribing it afterward is way more fugly.

Hans Passant
I didn't know that, Thanks
Samahu