UserControl Focus Issue - Focus() sometimes returns false
- by Craigger
I have a user control that behaves similar to a tab control.
The tab headers are UserControls that override Paint events to make them look custom.
In order to leverage the Validating events on various controls on our tab pages, when the user clicks on the tab headers, we set the Focus to the TabHeader user control.
I've noticed that Control.Focus() returns false sometimes but the documentation does not say why Control.Focus() will ever return false other than that the control can't receive focus. But I don't know why.
Here's what i see.
If my TabHeader UserControl does not contain any subcontrols, and I call myControl.Focus() from the MouseClick event, focus returns true.
If my TabHeader UserControl contains a subcontrol, and I call myControl.Focus() from the MouseClick event, focus returns false.
If my TabHeader UserControl contains a subcontrol, and I call myControl.subControl.Focus() from the myControl.MouseClick event, focus returns true.
Can someone explain this?