C# - The MessageBox's
Posted: Tue Apr 05, 2011 2:30 pm
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;