RESULT OF CLICKING NO BUTTON ON A MESSAGEBOX DIALOG CLASS.

Awadhendra Tiwari

Total Post:126

Points:882
Posted by  Awadhendra Tiwari
C# 
C#
 1496  View(s)
Ratings:
Rate this:
Hi all,
I have a following line of code
MessageBox.Show("Are you sure you want to download? Click 'YES' to Import (or) 'NO' to cancel", "Confirmation Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question);


I am trying to set it so that if the user clickes no, then it goes back to the original form and sets a button to visible and a label to invisible. I know the code to take care of the button and label, but I'm not sure how to take care of the result of the No button click.

Any help could be appreciated.
Thanks.
  1. James Smith

    Post:48

    Points:336
    Re: Result of clicking No button on a MessageBox dialog class.

    Hi Awadhendra,

    You can use DialogResult property for solving your problem. Like in following algorithm I will explain it.

    if(MessageBox.Show("Click","Confirmation",MessageBox.OKCancel,MessageBoxIcon.Warning)==DialogResult.OK)
    {
            //Write code if OK button is clicked.
    }
    else
    {
          //Write code if other button is clicked.
    }

    Thanks.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!