Do I really have to call Focus in OnMouseDown of my custom Control?
- by Thomas
I'm implementing a custom control that inherits from Control. I want it to be focusable (it's a kind of list box).
In the constructor, I do
SetStyle(ControlStyles.Selectable, true);
I can now use Tab to navigate to the control.
However, when the control receives a mouse click, it does not automatically claim focus. I can work around this, of course:
protected override void OnMouseDown(MouseEventArgs e)
{
Focus();
base.OnMouseDown(e);
}
But this feels like a kludge that should not be necessary. Is this really the way to go? Or is there some way to tell Control to claim focus automatically when it receives a mouse click?