views:

407

answers:

1

The WinForm SplitContainer gets the focus when it's dragged or clicked, while the Splitter does not. The side-effect of this, is that dragging a SplitContainer bar fires Leave/Validate on other controls, and I need to avoid this.

I already tried setting TabStop and CausesValidation to False, but with no success.

Is there a way to stop the SplitContainer from getting focused? (not a big deal, I can still use the old Splitter, but I lose some nice VS properties...)

A: 

Filini,

The only time that the splitcontainer would have focus is when you are actually moving the splitter. So I would so something like this in your validating and leave events.

private void Button_Leave(object sender, EventArgs e)
{
    if(SplitContainer.ContainsFocus)
        return;
}

I reproduced your issue and when I added the above it still calls the event of course, but the code execution doesn't occur because the SplitContainer has focus while you are moving the splitter.

Hope that helps.

joshlrogers
unfortunately, it's not fine for our architecture. I have a usercontrol which validates with the standard Validating event, and I cannot change its behaviour because other external controls glitch (that's the problem, when u move the splitcontainer bar, the leave/validatong events are fired, but the focus then remains on the bar, and my usercontrol freezes for some reason). the thing that bugs me is that this doesn't happen with a normal splitter, which gets moved without getting focus. eventually, I think I will just use a splitter
Filini
I have tried and I can not replicate the behavior of the focus remaining on the bar. In all of my attempts the focus immediately returned to the control that had the focus before clicking on the splitter. Sorry I was not able to help.
joshlrogers
Even if it worked (but I think that Validating fires anyway), I would have to put this code in all my Details UserControls (about 15 of them). It's not manageable. I hoped to find a solution with some code put in the SplitContainer, not in the other controls. Thanks anyway :)
Filini
having focus trigger validation is a bad design.
Warren P