I have the following code for clicking a button on a form:
private void btnOK_Click(object sender, EventArgs e)
{
if (this.txtProjectName.Text == "")
{
MessageBox.Show("No project name entered", "No Project Name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
btnOK.DialogResult = DialogResult.None;
}
else
{
this.btnOK.DialogResult = DialogResult.OK;
return;
}
}
If there is something in the text box, the form will be closed only the second time it is clicked. Is there a way to instantly close a form and pass it to DialogResult.OK?
thank
source
share