Page 1 of 1

C# - The MessageBox's

Posted: Tue Apr 05, 2011 2:30 pm
by Agust1337
Hello and welcome to my Messagebox's tutorial. I think the MessageBox function in C# is really hard to remember, so I want to let you people to make it not as hard to remember.

Simple MessageBox:
Code: Select all
MessageBox.Show("Some message")
Messagebox with Text & title
Code: Select all
MessageBox("This is the Text.", "This is the Title")
Messagebox with Yes and No buttons:
Code: Select all
DialogResult rslt = MessageBox.Show("Click Yes to do something and no to do something.", "Click Yes or No", MessageBoxButtons.YesNo);
if (rslt == DialogResult.Yes)
{
    //Do Something
}
else
{ 
    //If user hits No
}
Messagebox with Question Icon and Buttons:
Code: Select all
DialogResult rslt = MessageBox.Show("Do you want to do this? Click yes to do it and no to not too.", "Click Yes or No", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (rslt == DialogResult.Yes)
{
    //Do Something
}
else
{ 
    //If user hits No
}
Messagebox with Question Icon and Default Button:
Code: Select all
DialogResult rslt = MessageBox.Show("Do you want to do this? Click yes to do it and no to not too.", "Click Yes or No", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if (rslt == DialogResult.Yes)
{
    //Do Something
}
else
{ 
    //If user hits No
}
Hope you liked this :)
Have a happy coding cooll;

Re: C# - The MessageBox's

Posted: Tue Apr 05, 2011 5:11 pm
by mandai
I thought DialogResult was the return type of a MessageBox?
I don't see any objects under MessageBox.Buttons.
MessageBoxDeafultButton is spelt incorrectly.

Re: C# - The MessageBox's

Posted: Tue Apr 05, 2011 5:28 pm
by Agust1337
I will fix that maybe it was because I wrote it on the site not copied from C#

Re: C# - The MessageBox's

Posted: Sat May 14, 2011 10:05 pm
by Jelly
Thanks for this release.

Re: C# - The MessageBox's

Posted: Thu Jun 30, 2011 2:52 am
by mastercoderbb
Thanks for this amazing release might be useful XD