title: How to specify which control should be focused when a form opens?
body: <p>Whenever a Form is opened, the system automatically focuses one of the controls for you. As far as I can tell, the control that gets focus is the first enabled control in the tab order, as per Windows standard behavior.</p>
  
  <p>The question is how to change this at run time without having to dynamically reshuffle the tab order. For instance, some forms might want to vary the initially-focused control based on program logic, to put focus in the most appropriate control. If you just focus some other control inside your <code>OnLoad</code> handler, the default logic executes anyway and re-focuses the default control.</p>
  
  <p>If you're writing in C/C++ and using a raw window procedure or <a href="http://en.wikipedia.org/wiki/Microsoft_Foundation_Class_Library" rel="noreferrer">MFC</a>, you can return 0 (<code>FALSE</code>) from your <code>WM_INITDIALOG</code> handler, and the default focusing logic gets skipped. However, I can't find any way to do this in <a href="http://en.wikipedia.org/wiki/Windows_Forms" rel="noreferrer">Windows Forms</a>. The best I've come up with is to use <code>BeginInvoke</code> to set the focus after the <code>OnLoad</code> finishes, like so:</p>
  
  <pre><code>protected override void OnLoad( System.EventArgs e )
  {
      base.OnLoad( e );
      // ... code ...
      BeginInvoke( new MethodInvoker( () =&gt; this.someControl.Focus() ) );
  }
  </code></pre>
  
  <p>There must be some proper way to do this - what is it?</p>