title: Close Dialog with DateTimePicker
body: <p>We have a requirement to close forms, during auto log off. We are closing dialogs by iterating forms in <code>Application.OpenForms</code></p>
  
  <p>We cannot close a dialog if the dialog has a date time control (<code>DateTimePicker</code>) with the calender window is activive as shown in the following image</p>
  
  <p><a href="http://ww.functionx.com/vcnet/controls/images/Calendar4.gif" rel="nofollow">http://ww.functionx.com/vcnet/controls/images/Calendar4.gif</a></p>
  
  <p>I tried to close the form by calling <code>Close</code> Method. It didn't work. </p>
  
  <p>Then I sent the WM_CLOSE message to close the calender window as shown below after enumerating the windows and then called <code>Close</code> on the form. In this case the Calender window closed. But the form did not close</p>
  
  <pre><code>if (sb.ToString() == "SysMonthCal32")
  {
      SendMessage(hWnd, 0x0010, IntPtr.Zero, IntPtr.Zero);             
  }
  </code></pre>
  
  <p>In both cases, if I click on the Dialog it closed.</p>
  
  <p>How can I close the form?</p>