Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to handel the dialog Result

How to handel the dialog Result

Scheduled Pinned Locked Moved C#
tutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Iridania
    wrote on last edited by
    #1

    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

    J J 2 Replies Last reply
    0
    • I Iridania

      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

      J Offline
      J Offline
      Justin Jones 0
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • I Iridania

        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

        J Offline
        J Offline
        Judah Gabriel Himango
        wrote on last edited by
        #3

        If you want your form to not close when the No button is clicked, add an event handler to the Closing event instead of the Closed 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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups