How to Close the Message box, when the button NO is clicked? RRS feed

  • Question

  • Hi All,

    I have a windows form. It has a button named "Close".

    When i click the button, Message box is displayed with YES and NO buttons.

    If i click YES, i want to close the windows form. ( I am done with this)

    And, when i close NO, i just want to close the Message box but the Windows form must remain.

    Any help please.

    Thanks and regards


    Wednesday, April 17, 2013 6:00 PM


  • Hi,

    Try with the below code

    DialogResult = MessageBox.Show("Welcome to Conditional MessageBox \n
    Please select one option Yes/No)", 
    "Conditional", MessageBoxButtons.YesNo, 
        if (DialogResult == DialogResult.Yes)
           // code for yes action any function
            // any function or nothing to write here

    PS.Shakeer Hussain

    Wednesday, April 17, 2013 6:18 PM