What's the difference between Control.Select() and Control.Focus()?

Neil Barnwell picture Neil Barnwell · Apr 29, 2009 · Viewed 20.5k times · Source

In WinForms, to set focus to a specific control, I always seem to wind up calling Control.Select() and Control.Focus() to get it to work.

What is the difference, and is this the correct approach?

Answer

Jonas picture Jonas · Aug 5, 2009

Focus() is the low level function that actually sets the focus.

Select() is a higer-level method. It first looks iteratively upward in the control's parent hierarchy until it finds a container control. Then it sets that container's ActiveControl property (to the called control). The logic in those methods is not straightforward however, and there is special handling for UserControl containers.