title: Receiving password input using DialogShow() not working
body: <p>I am writing a WinForm application in C#. There is a <code>Form A</code> that opens <code>Form C</code> on <code>Button</code> click. Now, I want to add a password input screen <code>Form B</code> before opening <code>Form C</code>. Only if the password entered is correct will <code>Form C</code> open, and otherwise, show an error message. <code>Form B</code> just has a <code>TextBox</code> control and a <em>Verify</em> <code>Button</code> control.</p>
  
  <pre><code>/*Form A*/
  FormB fb;
  private void BtnClick(object sender, EventArgs e) {
      DialogResult result;
      //fb can open once at a time
      if(fb == null){
          fb = new FormB();
          fb.FormClosed += new FormClosedEventHandler(FormB_FormClosed);
  
          //This seems to be not working
          result = fb.ShowDialog();
      }
      else //FormB already open. Do nothing
          return;
  
      //Only if password entered is correct, proceed
      if(result == DialogResult.Yes){    //result == cancel 
          //Code to open Form C          //Program never reaches here
      }
  }
  
  //Upon closing FormB, reset it to null
  private void FormB_FormClosed(object sender, FormClosedEventArgs e){
      if(fb != null)
          fb = null;
  }
  
  /* Form B */
  private const string password = "xxxyyyzzz";
  private void BtnPW_Click(object sender, EventArgs e){
      bool result = Verify();
      if(result){
          BtnPW.DialogResult = DialogResult.Yes;
      }
      else{
          MessageBox.Show("Error: Incorrect password");
          BtnPW.DialogResult = DialogResult.No;
      }
      this.Close();             //Added
  }
  
  private bool Verify(){
      if(TxtBox.Text == password)
          return true;
      else
          return false;
  }
  </code></pre>
  
  <p>Can someone tell me what is wrong with this code? It never reaches the second <code>if</code> statement in <code>Form A</code>.</p>
  
  <p>Edit: Even if I enter the correct password and hit the button on <code>Form B</code>, <code>result</code> in <code>Form A</code> gets "DialogResult.Cancel`.</p>