How to handel the dialog Result
-
Hello i have something like this: This Method call me a form and disable the main menu so you can not call another form until you finish the one that you have active. private void tiendasToolStripMenuItem_Click(object sender, EventArgs e) { frmTienda Tienda = new frmTienda(); Tienda.MdiParent = this; Tienda.Show(); Tienda.Visible = true; //Here I'm Trying to handel the closing event so to be able to disable the main form(menu) Tienda.FormClosed +=new FormClosedEventHandler(Tienda_FormClosed); menuStrip1.Enabled = false; } //This is my method where i try to handel the "decision" that you want or not to close the form. private void Tienda_FormClosed(object sender, EventArgs e) { DialogResult r = MessageBox.Show("Seguro desea Cerrar esta ventana?", "Tienda", MessageBoxButtons.YesNo, MessageBoxIcon.Information); Form f = (Form)sender; if(r == DialogResult.Yes){ menuStrip1.Enabled = true; return; } } The thing is that i event i select No as a answer that i dont want to close the form it close anyway, so i would like another way to do it, eather disable the forms behind, or to take the answer of the messagebox so when i select no the form does not get close. :)
La Light
-
Hello i have something like this: This Method call me a form and disable the main menu so you can not call another form until you finish the one that you have active. private void tiendasToolStripMenuItem_Click(object sender, EventArgs e) { frmTienda Tienda = new frmTienda(); Tienda.MdiParent = this; Tienda.Show(); Tienda.Visible = true; //Here I'm Trying to handel the closing event so to be able to disable the main form(menu) Tienda.FormClosed +=new FormClosedEventHandler(Tienda_FormClosed); menuStrip1.Enabled = false; } //This is my method where i try to handel the "decision" that you want or not to close the form. private void Tienda_FormClosed(object sender, EventArgs e) { DialogResult r = MessageBox.Show("Seguro desea Cerrar esta ventana?", "Tienda", MessageBoxButtons.YesNo, MessageBoxIcon.Information); Form f = (Form)sender; if(r == DialogResult.Yes){ menuStrip1.Enabled = true; return; } } The thing is that i event i select No as a answer that i dont want to close the form it close anyway, so i would like another way to do it, eather disable the forms behind, or to take the answer of the messagebox so when i select no the form does not get close. :)
La Light
Iridania wrote:
This Method call me a form and disable the main menu so you can not call another form until you finish the one that you have active.
If I understand your question, It sounds like you want your form to behave as a modal dialog. I think what you want is "Tienda.ShowDialog()". Then you don't really need to disable/enable your menu or other forms. In your FormClosing event you can show your message box and if the user answers "No", set e.Cancel to true in your FormClosingEventArgs parameter. Any buttons you place on your form can be assigned a DialogResult property.
-
Hello i have something like this: This Method call me a form and disable the main menu so you can not call another form until you finish the one that you have active. private void tiendasToolStripMenuItem_Click(object sender, EventArgs e) { frmTienda Tienda = new frmTienda(); Tienda.MdiParent = this; Tienda.Show(); Tienda.Visible = true; //Here I'm Trying to handel the closing event so to be able to disable the main form(menu) Tienda.FormClosed +=new FormClosedEventHandler(Tienda_FormClosed); menuStrip1.Enabled = false; } //This is my method where i try to handel the "decision" that you want or not to close the form. private void Tienda_FormClosed(object sender, EventArgs e) { DialogResult r = MessageBox.Show("Seguro desea Cerrar esta ventana?", "Tienda", MessageBoxButtons.YesNo, MessageBoxIcon.Information); Form f = (Form)sender; if(r == DialogResult.Yes){ menuStrip1.Enabled = true; return; } } The thing is that i event i select No as a answer that i dont want to close the form it close anyway, so i would like another way to do it, eather disable the forms behind, or to take the answer of the messagebox so when i select no the form does not get close. :)
La Light
If you want your form to not close when the No button is clicked, add an event handler to the
Closing
event instead of theClosed
event. Your code would look like this:Tienda.FormClosinng += new FormClosingEventHandler(Tienda_FormClosed);
...
private void Tienda_FormClosing(object sender, FormClosingEventArgs)
{
DialogResult result = MessageBox.Show("Seguro desea Cerrar esta ventana?", "Tienda", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if(result == DialogResult.No)
{
e.Cancel = true; // this will prevent the form from closing.
}
}Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango