title: System.ObjectDisposedException from simple form display
body: <p>I'm trying to figure out how when simply showing a WinForms dialog (code below) I get the following Exception and callstack. This doesn't happen all the time, but I'm seeing it in my exception logs. Any ideas? I can't figure out what would be referencing a disposed object? </p>
  
  <p>I've verified (via the rest of the callstack) that the application is not shutting down, it is running normally.</p>
  
  <pre><code>System.ObjectDisposedException: Cannot access a disposed object.    
  Object name: 'MainForm'.    
     at System.Windows.Forms.Control.CreateHandle()    
     at System.Windows.Forms.Form.CreateHandle()    
     at System.Windows.Forms.Control.get_Handle()    
     at System.Windows.Forms.Control.GetSafeHandle(IWin32Window window)    
     at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)    
     at MyApp.MainForm.PromptForProfile()    
     at MyApp.MainForm.LoadProfile()    
     at MyApp.MainForm.barButtonItem1_ItemClick(Object sender, ItemClickEventArgs e)
  </code></pre>
  
  <p>This is the code for the dialog being displayed. The only "goofy" code is probably the textPassword_KeyDown handler. I should probably pull the code I want out and not call btnOK_Click that way.  </p>
  
  <pre><code>public partial class ProfileForm : DevExpress.XtraEditors.XtraForm
     {
        public string _username;
        public string _password;
  
        public ProfileForm()
        {
           InitializeComponent();
        }
  
        private void btnOK_Click( object sender, EventArgs e )
        {
           _username = textUsername.Text;
           _password = textPassword.Text;
        }
  
        private void textPassword_KeyDown( object sender, KeyEventArgs e )
        {
           if ( e.KeyCode == Keys.Enter )
           {
              btnOK_Click( sender, null );
              this.DialogResult = DialogResult.OK;
              e.Handled = true;
           }
        }
  
        private void hyperLinkEdit1_Click( object sender, EventArgs e )
        {
           // show the proxy settings dialog
           ProxyForm pform = new ProxyForm();         
           pform.ShowDialog();         
        }
     }
  </code></pre>