C# MessageBox

MessageBox.Show() show a specific message by popping up a window on the screen.

using System.Windows.Forms;
int sum=0;
for (int i=0;i < 10;i++)
{
sum += i;
}
MessageBox.Show(sum.ToString()); //45


To add title string to the message box:
MessageBox.Show(sum.ToString(),"The sum is:");


To add Yes or No selection button:
MessageBox.Show(sum.ToString(), "The sum is:",MessageBoxButtons.YesNo);


The MessageBox returns a DialogResult value:
DialogResult dr = MessageBox.Show(sum.ToString(), "The sum is:",MessageBoxButtons.YesNo);
if (dr == DialogResult.Yes) {...}
else if (dr == DialogResult.No) {...}



endmemo.com © 2024  | Terms of Use | Privacy | Home