title: Keep track of Window being Last Focus
body: <p>The VB.Net program I am creating dynamically created Panels within a <code>TableLayoutPanel</code> and adds form elements to them.  I need to keep track of what the last of these Panels to have focus was, and am hitting a bit of a brick wall.</p>
  
  <p>I have tried creating an event class for when the Panel has focus:</p>
  
  <pre><code>Private Sub Self_GotFocus(ByVal sender As Object, ByVal e As EventArgs) Handles Me.GotFocus
      GlobalController.Focus_Target = Me.Name
  End Sub
  </code></pre>
  
  <p>The classes for each Panel Inherit from <code>Windows.Forms.FlowLayoutPanel</code>, which I why I have the call being <code>Me.GotFocus</code>.  Additionally, the <code>GlobalController</code> class is just a class meant to hold global variables for the program.</p>
  
  <p>Now the issue I am having, is that this event only seems to trigger when I actually am deleting the panel.  When the panel is created, if I click on it, or any of it's form elements, the event never gets triggered (I debugged the program with a breakpoint).</p>
  
  <p>I can't exactly figure out why this only triggers when I go to delete the panel, and not at any other time.  Is there another event I should be using instead of <code>GotFocus</code>?</p>