UserControl Focus Issue - Focus() sometimes returns false

Posted by Craigger on Stack Overflow See other posts from Stack Overflow or by Craigger
Published on 2008-12-30T19:55:55Z Indexed on 2010/03/25 14:03 UTC
Read the original article Hit count: 813

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about usercontrols