Click here to Skip to main content
15,897,291 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I had create a MessageBox with OK and Cancel button. How do i know User is click on which button?
Posted

DialogResult d = MessageBox.Show("are you shure", "delete", MessageBoxButtons.YesNo);
                if (d == DialogResult.Yes)
                {


this is very easy :) :)
 
Share this answer
 
DialogResult dresult = MessageBox.Show("Are you sure ","Alert"
                              ,MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
if (dresult == DialogResult.OK)
{
    // Do something
}
 
Share this answer
 
v2
string message = "Message goes here";
string caption = "Warning !";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;
 // Displays the MessageBox.
                    
result = MessageBox.Show(this, message, caption, buttons, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
 if (result == DialogResult.Yes)
 {
//actions
 }
else
{
//actions

}


hope this helps!
 
Share this answer
 
check if the dialog result is OK

DialogResult::OK
 
Share this answer
 
Check the return value of the MessageBox method, see, for instance [^].
:)
 
Share this answer
 
Simply check the DialogResult values from the MessageBox.Show function.

C#
if (DialogResult.OK == MessageBox.Show(...))
{
    // yes OK was pressed
}
else
{
    // OK wasn't pressed
}
 
Share this answer
 
int nResult = AfxMessageBox(_T("Are you Sure to quit?"), MB_OKCANCEL|MB_ICONQUESTION);

if(nResult == IDOK)
{
//ok was clicked
}
else
{
//cancel was clicked
}
 
Share this answer
 
I have same question but I am using AfxMessageBox and I need to know what is the code I need to put between the code mentioned below:

if(nresult ==IDOK)
{
//code for OK
}
{
//code for CANCEL
}


I like show .exe file if click OK and click on Cancel terminate the session.

Thank you very much
 
Share this answer
 
v4
Comments
Simon Bang Terkildsen 28-Sep-11 15:27pm    
Do not post a question as a solution, please.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900