title: c# Focus() appears to trigger the Leave() method
body: <p>The last time I did any serious programming was 25 years ago in C with a copy of Kernighan and Ritchie. Please be gentle with an aging amateur!</p>
  
  <p>In essence, it's the old nullable date picker thing. I have a solution working perfectly well with one exception. I am using a combination of a masked TextBox and a MonthCalendar. The masked TextBox simply displays any value (including null) from a data set and accepts values from the calendar. Pressing backspace in the calendar clears the masked TextBox. All This is very straightforward. All I need to do now is to hide the calendar when it loses focus. A simple example demonstrates the problem I have:</p>
  
  <p>Create a form with a text box to take the initial focus, a masked text box and a hidden MonthCalendar. In the Enter event of the masked text box, I have the following code:</p>
  
  <pre><code>monthCalendar1.Visible = true;
  monthCalendar1.Focus();
  </code></pre>
  
  <p>My intention was to put the following code into the Leave event of the MonthCalendar:</p>
  
  <pre><code>monthCalendar1.Visible = false;
  </code></pre>
  
  <p>For some reason, this code is triggered as soon as the calendar gets the focus and the calendar is hidden again immediately. Debugging confirms that this code is triggered. If the Leave event is empty, the MonthCalendar does indeed get the focus and retains it, because it is possible to navigate the calendar with the arrow keys.</p>
  
  <p>Can anyone explain this behavior to an old fogey or, even better, give me a pointer to what I'm trying to do.</p>
  
  <p>Many thanks in advance.</p>