C# - The MessageBox's
All tutorials created in C# to be posted in here.
5 posts
Page 1 of 1
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:
Have a happy coding cooll;
Simple MessageBox:
Code: Select all
Messagebox with Text & title
MessageBox.Show("Some message")
Code: Select all
Messagebox with Yes and No buttons:
MessageBox("This is the Text.", "This is the Title")
Code: Select all
Messagebox with Question Icon and Buttons:
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
}
Code: Select all
Messagebox with Question Icon and Default Button:
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
}
Code: Select all
Hope you liked this 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
}

Have a happy coding cooll;
Last edited by Agust1337 on Tue Apr 05, 2011 5:30 pm, edited 1 time in total.
I thought DialogResult was the return type of a MessageBox?
I don't see any objects under MessageBox.Buttons.
MessageBoxDeafultButton is spelt incorrectly.
I don't see any objects under MessageBox.Buttons.
MessageBoxDeafultButton is spelt incorrectly.
I will fix that maybe it was because I wrote it on the site not copied from C#
5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023