title: What is the preferred way to find focused control in WinForms app?
body: <p>What is the preferred/easiest way to find the control that is currently receiving user (keyboard) input in WinForms?</p>
  
  <p>So far I have come up with the following:</p>
  
  <pre><code>public static Control FindFocusedControl(Control control)
  {
      var container = control as ContainerControl;
      return (null != container
          ? FindFocusedControl(container.ActiveControl)
          : control);
  }
  </code></pre>
  
  <p>From a form, this can be called simply as (in .NET 3.5+ this could even be defined as an extension method on the form) -</p>
  
  <pre><code>var focused = FindFocusedControl(this);
  </code></pre>
  
  <p>Is this appropriate?</p>
  
  <p>Is there a built-in method that I should be using instead?</p>
  
  <p>Note that a single call to ActiveControl is not enough when hierarchies are used. Imagine:</p>
  
  <pre><code>Form
      TableLayoutPanel
          FlowLayoutPanel
              TextBox (focused)
  </code></pre>
  
  <p>(formInstance).ActiveControl will return reference to TableLayoutPanel, not the TextBox (because ActiveControl seems to only be returning immediate active child in the control tree, while I'm looking for the leaf control).</p>