I have a few checkboxes representing people. Something like this:
[ ] George
[ ] Sam
[ ] Steve
[ ] Lisa
Each can be checked individually, and of course it’s also possible to check none at all. Code runs upon a change in check state. That code uses the state of all checkboxes in its algorithm.
However, I would like them to ALSO behave like radiobuttons upon doubleclick. That is, if you doubleclick one, it should become checked (regardless of its previous state) and all others will become un-checked.
Unfortunately there’s no doubleclick event for a checkbox. So clearly, I need to simulate a doubleclick by using mousedown (or mouse up) and a combination of timers, a stopwatch, etc.
Ultimately I know I’ll find a solution through experimentation, so if I come up with a good solution I’ll post it here. But I have a feeling others have “simulated doubleclicks” before and if someone can post a good snippet for creating such an event from the mousedown event, that would be great.
P.S. The snippet should somehow involve SystmInformation.DoubleClickTime. (This is the number of milliseconds that distinguishes a doubleclick from “two singleclicks”. It may be different from one machine to the next.) Code for a single click should NOT run until that much time has elapsed, to ensure that a doubleclick isn’t pending. (Because as I mentioned, the code uses the state of all checkboxes.)
P.P.S. I’m using VB.NET Express 2008 for a winforms app, but I can probably translate form C# if needed and I figure this probably applies all across .NET platforms.
Surgery is required, the CheckBox class was written to assume that standard click and double-click behavior is turned off. This code worked, you’ll have to give up on the MouseUp event:
An event handler could look like this:
There might be some surgery side-effects, I didn’t see any but didn’t test it thoroughly. I recommend you do not actually do this, the feature is massively undiscoverable. No user will ever realize that a double-click now does something special.