MessageBox Examples


Example 1 - Information

System.Windows.Forms.MessageBox.Show( 
   "This is a message",
   "Message Box Caption",
   System.Windows.Forms.MessageBoxButtons.OK,
   System.Windows.Forms.MessageBoxIcon.Information);
alt text

Example 2 - Multiple Lines

System.Windows.Forms.MessageBox.Show( 
   "This is a message" +
   System.Environment.NewLine +
   System.Environment.NewLine +
   "Displayed over multiple lines",
   "Message Box Caption",
   System.Windows.Forms.MessageBoxButtons.OK,
   System.Windows.Forms.MessageBoxIcon.Information);
alt text

Example 3 - Exclamation / Warning

System.Windows.Forms.MessageBox.Show( 
   "This is a message",
   "Message Box Caption",
   System.Windows.Forms.MessageBoxButtons.OKCancel,
   System.Windows.Forms.MessageBoxIcon.Exclamation);
alt text

Example 4 - Error / Stop / Hand

System.Windows.Forms.MessageBox.Show( 
   "This is a message",
   "Message Box Caption",
   System.Windows.Forms.MessageBoxButtons.OKCancel,
   System.Windows.Forms.MessageBoxIcon.Error);
alt text

Example 5 - Question

System.Windows.Forms.DialogResult oResult; 

oResult = System.Windows.Forms.MessageBox.Show(
   "This is a question ?",
   "Message Box Caption",
   System.Windows.Forms.MessageBoxButtons.YesNoCancel,
   System.Windows.Forms.MessageBoxIcon.Question);

if (oResult == System.Windows.Forms.DialogResult.Yes)
{ }
if (oResult == System.Windows.Forms.DialogResult.No)
{ }
if (oResult == System.Windows.Forms.DialogResult.Cancel)
{ }
alt text

Default Buttons

MessageBoxDefaultButton.Button1, 

Message Options

MessageBoxOptions.RightAlign, 

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext