title: Find out the control with last focus
body: <p>I have a c# windows forms application with several textboxes and a button. I would like to find out the textbox which has focus and do something with it. I have written following code but of course it won't work because the button will get focus as soon as it is pressed.</p>
  
  <pre><code>private void button1_MouseDown(object sender, MouseEventArgs e)
  {
      foreach (Control t in this.Controls)
      {
          if (t is TextBox)
          {
              if (t.Focused)
              {
                  MessageBox.Show(t.Name);
              }
          }
      }
  }
  </code></pre>