Message Box is used to display a user-friendly message to the user, and also used to display a dialogue box.
Example
See the below example to know about "how to use message box".
Step 1
Design the form as shown in the below figure.
Step 2
Double click on the Save button and write the below code under the click event of the Save button.
[csharp]
private void btnSave_Click(object sender, EventArgs e)
{
if (txtName.Text == "")
{
MessageBox.Show("Please Enter the Name");
}
else
{
MessageBox.Show("Successfully Saved");
}
}
[/csharp]
Step 3
Press f5 to run the application. Then, The following window will appear.
Step 4
Enter the name and click on Save button, Then the message box will appear as shown in the below figure.
Step 5
Click on Save button without entering the Name. Then the message box will appearas shown in the below figure.