Hi Arjang, I suggested this approach as it had the least change required for existing code and it cleaning isolated the code in one procedure (plus a property or field in practice).
If I were doing it from scratch I would avoid using hidden UI. Either way though, you'd need to do some event management to allow the single UI to be updated via code without triggering a "user changed" event. Cheers. James. -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Arjang Assadi Sent: Thursday, 5 May 2011 10:49 To: ozDotNet Subject: Re: Can you detect a checkbox state chnage by user not code? Hi James, What about using a bool property where it either gets sets or read by the check box and programmatic changing of that property that updates the check box without invoking the programatic dependent or user dependent code? Using hidden GUI controls sounds like an oxymoron. Regards Arjang On 4 May 2011 18:16, James Chapman-Smith <[email protected]> wrote: > How about an approach of using two check boxes - one hidden and one visible? > > > > Assuming I have a check box called "OzDotNetSubscriber" hide it (ie > `.Visible = false`), and then add in a new check box called > "OzDotNetSubscriberVisible" and place it on the UI to replace the hidden > original check box. > > > > Now, since the original check box is not visible the user cannot change it. > They can change the new visible check box though. Now it's just a matter of > keeping the two in sync and tracking which of the two initiated the change. > > > > Here's the code that does it: > > > > // Was the check box changed by the user (or by code)? > > var OzDotNetSubscriberChangedByUser = false; > > > > // Check box checked changed event handler declarations > > var userChangeHandler = (EventHandler)null; > > var codeChangeHandler = (EventHandler)null; > > > > // Defined after declarations because they reference each other > > > > userChangeHandler = (s, e) => > > { > > this.OzDotNetSubscriber.CheckedChanged -= codeChangeHandler; > > this.OzDotNetSubscriber.Checked = > this.OzDotNetSubscriberVisible.Checked; > > this.OzDotNetSubscriber.CheckedChanged += codeChangeHandler; > > OzDotNetSubscriberChangedByUser = true; > > }; > > > > codeChangeHandler = (s, e) => > > { > > this.OzDotNetSubscriberVisible.CheckedChanged -= userChangeHandler; > > this.OzDotNetSubscriberVisible.Checked = > this.OzDotNetSubscriber.Checked; > > this.OzDotNetSubscriberVisible.CheckedChanged += userChangeHandler; > > OzDotNetSubscriberChangedByUser = false; > > }; > > > > // Wire up events > > this.OzDotNetSubscriberVisible.CheckedChanged += userChangeHandler; > > this.OzDotNetSubscriber.CheckedChanged += codeChangeHandler; > > > > Does that work for you? > > > > Cheers. > > > > James. > > > > > > From: [email protected] [mailto:[email protected]] > On Behalf Of Anthony > Sent: Wednesday, 4 May 2011 12:22 > To: 'ozDotNet' > Subject: Can you detect a checkbox state chnage by user not code? > > > > Is it possible to determine if a check box has been clicked by a user and > not by code. > > > > regards > > Anthony (*12QWERNB*) > > > >
