title: How to return Dialog result ok from button click only if some condition are met
body: <p>I am tryin to create a costume messagebox with datavalidation(username , Password) in Visual studio winforms
  I already made another one with the password only that will take the text box text encrypt it and compare it the the stored encrypted password</p>
  
  <pre><code>private void TextBoxPass_TextChanged(object sender,EventArgs e)
  {
      //Storedpassword is the stored password and ButtonOk is the confirm Button
      //Encrypt is the encription function
      if(Encrypt(TextBoxPass.Text)==StoredPassword)
          ButtonOk.DialogueResult=DialogueResult.OK;
  }
  </code></pre>
  
  <p>this way i can easily capture the returned dialogue result.
  but in the case where i have to verify Username And password from the database, I can't use the text change event cause it will connect to the database eachtime the User name or password text are changed so i tried the code below
  This Part is the Dialogue result I call in the class passwordvalidation</p>
  
  <pre><code>public static DialogResult UserLogin()
      {
          using (FORMS.USER_LOGIN MSGPASS = new FORMS.USER_LOGIN())
          {
              DialogResult DLresult = MSGPASS.ShowDialog();
              return DLresult;
          }
      }
  </code></pre>
  
  <p>And this is the form USER_LOGIN form code</p>
  
  <pre><code>private DialogResult drslt(string USRNME,string Pss)
      {
          //Some code to Verify UserName and Password 
          //from database and return DataTable dt
          DialogResult DR;
          //COMPARE
          if (dt.Rows.Count == 1)
          {
              //login successful
              DR = DialogResult.OK;  
          }
          else
          {
              //login unsuccussful
              DR = DialogResult.None;
          }
           return DR;
      }
  private void BULCONFIRM_Click(object sender, EventArgs e)
      {
          DialogResult DRS =drslt(TBULNAME.Text,TBULPassword.Text);
          if (DRS == DialogResult.OK)
              this.Close();
          else
              CLASS.CostumeMessages.ShowMessage("","",
                      MessageBoxButtons.OK, MessageBoxIcon.Warning);
      }
  </code></pre>
  
  <p>when I try to capture Dialogue result, it close the ShowDialogue form but it doesn't give the correct Dialogue result value</p>
  
  <pre><code>//Calling the DialogueResult
  if(PasswordValidation.UserLogin()==DialogResult.OK)
              //do some stuff;
  </code></pre>
  
  <p>at the same time when I use the button Cancel which has the dialogueresult proprety =Cancel, the result works normally.
  So what i want to know is if there is a mistake that i am making or if there is another way to return DialogueResult.OK when I click the CONFIRM button??</p>