I have a UserControl-derived control with several sub-controls (here: three docked labels). In order to react on a click anywhere on the UserControl, I override WndProc() and look for
WM_PARENTNOTIFY/WM_LBUTTONCLICK
— this was suggested on MSDN, and it does work well.
The reaction on the user’s mouseclick is to open a (modal) popup dialog. However, when I try to implement this, a strange behaviour shows up: Sometimes, the dialog flickers several times, and a Windows sound occurs. After closing the dialog, the user has to click into the main window (containing the UserControl) to re-set the focus. Sometimes, no flicker and no sound, but the main form loses focus as well.
In contrast to this, the button next to the UserControl also opens that popup dialog. There is no flicker and no sound, and after closing the popup the main window automatically has the focus again.
What’s wrong with the UserControl/WndProc construction?
I’m including an example project (VS2008) to illustrate the behaviour: (via DropBox)
Try using
BeginInvoketo start the event after the WndProc method has finished: