title: Taskbar Minimize C# Windows Form Problem
body: <p>I have a Windows Form application that, when the form is Activated, Deactivated, or SizeChanged, the form does something.  It's rather specific.  For example:</p>
  
  <p><strong>Form Activated</strong>:  Will set the variable <code>isActive</code> to true, and focus the input to an input box for someone to enter something too.</p>
  
  <p><strong>Form Deactivated</strong>:  Will set the variable <code>isActive</code> to false, so that any focus changes in the application (caused by remote machine messages, chat messages, etc), does not steal focus from other applications.</p>
  
  <p>Right now, I have my <code>webBrowser1.Focus()</code> command inside of the <code>Form Activated</code> event which isn't ideal, as when you click on the taskbar icon, it tries to minimize, but since it focuses back to the web browser, the form is then restored/activated again.</p>
  
  <p>I did some searching here on Stack Overflow, and found the following information:</p>
  
  <p><strong>Edited for the below information:</strong></p>
  
  <p>I did find this information in another post here on Stack Overflow:</p>
  
  <pre><code>protected void OnActivateApp(bool activate)
  {
      Console.WriteLine("Activate {0}", activate);
  }
  
  protected override void WndProc(ref System.Windows.Forms.Message m)
  {
      // Trap WM_ACTIVATEAPP
      if (m.Msg == 0x1c) OnActivateApp(m.WParam != IntPtr.Zero);
      base.WndProc(ref m);
  }
  </code></pre>
  
  <p>But the behavior is similar to the problem I'm seeing with the above 2 events.  When the taskbar icon is CLICKED, the form does catch the Deactivated:</p>
  
  <blockquote>
    <p>Activate False</p>
  </blockquote>
  
  <p>But then immediately, it does this:</p>
  
  <blockquote>
    <p>Activate True</p>
  </blockquote>
  
  <p>It would appear, that when you minimize a window with the taskbar button, it still remains as the 'focused' application until you click on another application.  </p>
  
  <p>One of the posts did suggest I capture the <code>GotFocus</code> of the form, but there is no event that I can find for a form level for <code>GotFocus</code>, as <code>GotFocus</code> is derived from a control, not an application form.  </p>
  
  <p><strong>Question:</strong>  How do I allow the form to be minimized with the taskbar button, and when the form is then reshown, get it to do the <code>webBrowser1.Focus()</code> command to put the focus where it should be?</p>