Click here to Skip to main content
15,887,392 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Sir the problem is,

I m making a notepad but i don't no how to use the properties of MessageBoxButtons to check the condition. Because it is require in save coding to check the condition..

Sir plz tell m the solution of it as soon as possible...

thankuu in advance...
Posted
Comments
#realJSOP 17-Feb-11 8:43am    
Your question makes no sense whatsoever.
Ashish Tyagi 40 17-Feb-11 13:28pm    
Hi Tyagi ji. You can choose any of these
MessageBoxButtons.AbortRetryIgnore;
MessageBoxButtons.OK;
MessageBoxButtons.OKCancel;
MessageBoxButtons.RetryCancel;
MessageBoxButtons.YesNo;
MessageBoxButtons.YesNoCancel;
for the buttons you want to show.
Good Luck :)

Something like this, perhaps:

C#
if (MessageBox.Show("Quit Notepad Studio without saving?", "Quit?",
    MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
{
    this.Close();
}
 
Share this answer
 
Comments
JF2015 17-Feb-11 8:44am    
Simple and informative! 5+
Nish Nishant 17-Feb-11 8:45am    
Thanks.
Shristi Tyagi 17-Feb-11 9:12am    
thnxx sir...
but m to ask that how cn we use it only either for 'yes' or 'no'?
Nish Nishant 17-Feb-11 9:13am    
No, you can certainly use any of the other options available in the MessageBoxButtons enumeration.
Shristi Tyagi 17-Feb-11 9:18am    
means we cnt't use the MessageBoxButtons indiviually?
Nishant Sivakumar has given a very good example.
Here is another one with multiple cases.
C#
//{
     DialogResult DialogResult = DialogResult.None ;
     DialogResult = MessageBox.Show("Ask", "Title",
             MessageBoxButtons.YesNoCancel);
     switch(DialogResult)
     {
         case DialogResult.Yes:
             //do something
         break;
         case DialogResult.No :
             //do something
         break;
         case DialogResult.Cancel :
             //do something
         break;
         //add or remove according to your needs
         default:
             //do something
         break;
     }
 //}
 
Share this answer
 
Comments
Ashish Tyagi 40 17-Feb-11 13:19pm    
Nice example buddy +5 from me

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