title: Set Focus to Form After Me.Show
body: <p>I've come across a peculiar focusing issue. I have created the following "search" program:</p>
  
  <ol>
  <li>It runs in the background.</li>
  <li>When you double-tap the <kbd>Ctrl</kbd> key it becomes visible.</li>
  <li>You can type in the textbox because the form has focus.</li>
  <li>If the form loses focus (I click on my desktop, for example), it disappears after 3 seconds.</li>
  <li>I double-tap the <kbd>Ctrl</kbd> key again, and again it becomes visible.</li>
  <li>But this time, no matter what I try, the form is not focused and I cannot type in the textbox without first manually clicking on the form.</li>
  </ol>
  
  <p>What's particularly interesting is that when I run this program in debug mode from Visual Studios, the program regains focus upon double-tapping <kbd>Ctrl</kbd> key and becoming visible, and I can immediately start typing in the text box. However, when I build this program and run it alone, the program appears but does not regain focus upon double-tapping <kbd>Ctrl</kbd> key, and therefore I cannot type in the text box until I manually click the form.</p>
  
  <p>After Me.Show() I have tried:</p>
  
  <ul>
  <li>Me.Focus()</li>
  <li>Me.Validate()</li>
  <li>Me.Select()</li>
  <li>Textbox1.Select()</li>
  <li>Textbox1.Focus()</li>
  </ul>
  
  <p>The form is topmost and normally running in administrator, but the same problem arises regardless.</p>
  
  <p>The issue can be recreated in a more simple manner. Create a form with</p>
  
  <ul>
  <li>Button ("Button1")</li>
  <li>TextBox</li>
  <li>Two timers ("hideForm", "showForm") both with intervals of 1000</li>
  </ul>
  
  <p>Code:</p>
  
  <pre><code>Public Class Form1
  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      hideForm.Start()
      sender.Enabled = False
  End Sub
  
  Private Sub hideForm_Tick(sender As Object, e As EventArgs) Handles hideForm.Tick
      Me.Hide()
      hideForm.Stop()
      showForm.Start()
  End Sub
  
  Private Sub showForm_Tick(sender As Object, e As EventArgs) Handles showForm.Tick
      showForm.Stop()
      Me.Show()
      Me.Activate()
  End Sub
  End Class
  </code></pre>
  
  <p>Click the button, and immediately click on a different window (so the form loses focus). Wait until the form is hidden and shown again. The textbox should have focus. Try typing.</p>
  
  <p><strong>If the program is run in debugging mode in Visual Studios, it works as expected. If you build the program and run it outside of VS, the form will reappear without focus, and you cannot type in the textbox without manually selecting the form.</strong></p>
  
  <p>Sorry for the long-winded explanation. It's a difficult issue to properly describe.</p>