How to Use MessageBox.Show Method in C#

MessageBox is a class and Show is a function that displays a message in a small window in the center of the Form.
MessageBox is used to provide confirmations of a task being done or to provide warnings before a task is done.
Figure 1 Windows Form

Figure 2 Code Snippet

Figure 3 Showing the output

By default the OK Button will be shown.

Figure 4 Second and third argument MessageBoxIcon  
Figure 5 Fourth argument specifies MessageBoxIcon
Dialog Result
DialogResult is an enumeration of the possible return values of a dialog box including a MessageBox.
Figure 6
Design phase
  1. private void button1_Click(object sender, EventArgs e)      
  2.        {      
  3.            DialogResult d;      
  4.           d=MessageBox.Show("Welcome to C# Corner","Learn C#",MessageBoxButtons.YesNo,MessageBoxIcon.Information);      
  5.            if(d==DialogResult.Yes)      
  6.            {      
  7.                Close();      
  8.            }      
  9.        }      
Figure 7 Final output
Thank you.

Up Next
    Ebook Download
    View all
    View all