title: Form last location when minimized to system tray loop
body: <p>I am using the application setting Location of the form to store the application last location so that when the app is opened again, it opens exactly where I left off.</p>
  <p>I also use the NotifyIcon control to send the application to the system tray when minimized. An odd behavior is if the app is in the system tray when it is killed (ie through task manager) then the next time the app is opened, it opens to the system tray. Which is fine (although I prefer it to open normally on the screen), but when you double click on the icon in the system tray the app moves to the task bar, and if I click the icon on the taskbar it moves back to the system tray and then gets stuck in an infinite loop.</p>
  <p>I am using the form_resize method as such:</p>
  <pre><code>Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
      If Me.WindowState = FormWindowState.Minimized Then
          NotifyIcon1.Visible = True
          NotifyIcon1.Icon = Me.Icon
          NotifyIcon1.ShowBalloonTip(50000)
          ShowInTaskbar = False
      End If
  End Sub
  </code></pre>
  <p>And then setting the doubleclick method of NotifyIcon as:</p>
  <pre><code>Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
      ShowInTaskbar = True
      Me.WindowState = FormWindowState.Normal
      NotifyIcon1.Visible = False
  End Sub
  </code></pre>
  <p>Everything works fine if I don't use the last location setting but that means the application opens up in random places. As soon as I add the last location setting it exhibits the behavior above.</p>
  <p>Any ides what I'm doing wrong?</p>