views:

123

answers:

1

In C#/Winforms how do I set the default focus when my application starts?

+8  A: 

The one with the minimum tab index automatically gets the focus (assuming the TabStop property is set to true). Just set the tab indices appropriately.

By the way, Visual Studio provides a way to easily set tab indices by just clicking on the controls in the order you want. You can activate this feature by choosing "Tab Order" option in the "View" menu when you are in the form design view.

You can also manually give the focus to a control by calling its Focus method when the form loads.

Mehrdad Afshari
You want to call Select() instead of Focus(), Focus is a low-level method intended primarily for custom control authors. See: http://stackoverflow.com/questions/802722/whats-the-difference-between-control-select-and-control-focus
blak3r