title: Why does a form displayed by PowerShell sometimes not show up?
body: <p>When I create a form (window) in PowerShell, I can usually display the form using .ShowDialog():</p>
  
  <pre><code>$form = New-Object System.Windows.Forms.Form
  $form.ShowDialog()
  </code></pre>
  
  <p>.Visible is set to False before and after .ShowDialog().</p>
  
  <p>But when I do a .Show() nothing is displayed on the screen:</p>
  
  <pre><code>$form.Show()
  </code></pre>
  
  <p>And .Visible is now set to True (presumably because .Show() made the form officially visible.)</p>
  
  <p>When I now try to .ShowDialog() the form again, I get the following error message:</p>
  
  <p>"Form that is already visible cannot be displayed as a modal dialog box. Set the form's visible property to false before calling showDialog."</p>
  
  <p>But when I follow the instructions to .ShowDialog() again</p>
  
  <pre><code>$form.Visible=0
  $form.ShowDialog()
  </code></pre>
  
  <p>the result is that nothing is displayed on the screen and PowerShell hangs and cannot recover (ctrl-c doesn't seem to work). I assume this is because the form is being displayed modally somewhere where I cannot see it (or tab to it). But why?</p>
  
  <p>The coordinates of the form haven't changed. So how does the form decide when it is physically visible and when it isn't?</p>