Note that there are some explanatory texts on larger screens.

plurals
  1. POForm close after button click with no this.close() call
    text
    copied!<p>This is a simple question, but i don´t know where is the problem. I have a form that have some code, when i click into "crear" button, in that button i call to the function "Comprobar" that cheks if the textboxs are empty, if "Comprobar" is false then i show a message.</p> <p>The problem: After clicking the button "Crear" the form show the message (if all are empty) and then the form close. </p> <p>Here is the code</p> <pre><code>public partial class FrmNuevaCita : MetroForm { DataTools mytool = new DataTools(); DataSet ds = new DataSet(); BindingSource bs = new BindingSource(); // string searchDate = ""; int codigoPaciente = -1; FrmBuscarPaciente BuscarPaciente = new FrmBuscarPaciente(); public FrmNuevaCita() { InitializeComponent(); BuscarPaciente.SetCode += new EventHandler(YouCliked); } private void YouCliked(object sender, EventArgs e) { codigoPaciente = BuscarPaciente.GetCodigoPaciente; //MessageBox.Show("Codigito es " + codigoPacienteActual.ToString()); txtPaciente.Text = codigoPaciente.ToString(); } public DateTime SetDate { set { dtpFechaCita.Value = value; } } private void mbCancelar_Click(object sender, EventArgs e) { this.Close(); } private void metroRadioButton_CheckedChanged(object sender, EventArgs e) { this.cmbHora.Items.Clear(); if (metroRadioButton1.Checked == true) { this.cmbHora.Items.AddRange(new object[] {"8:00","8:30","9:00","9:30","10:00","10:30","11:00","11:30"}); } else if (metroRadioButton2.Checked == true) { this.cmbHora.Items.AddRange(new object[] { "12:00", "12:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30","16:00","16:30","17:00","17:30","18:00","18:30","19:00" }); } } private void mtBuscar_Click(object sender, EventArgs e) { BuscarPaciente.Show(); } private void mbCrear_Click(object sender, EventArgs e) { if (Comprobar()==false) MessageBox.Show("Por favor complete todos los campos"); } private bool Comprobar() { bool result = false; if (txtPaciente.Text.Trim().Length != 0 &amp;&amp; txtObservaciones.Text.Trim().Length != 0 &amp;&amp; cmbHora.Text.Trim().Length != 0) result = true; return result; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload