Windows Application - SPLessons

Win App Using Message Box

Home > Lesson > Chapter 19
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Win App Using Message Box

Windows Application Using Message Box

Message box uses

shape Description

Message Box is used to display a user-friendly message to the user, and also used to display a dialogue box.

shape Example

See the below example to know about "how to use message box".

shape Step 1

Design the form as shown in the below figure.

shape 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]

shape Step 3

Press f5 to run the application. Then, The following window will appear.

shape Step 4

Enter the name and click on Save button, Then the message box will appear as shown in the below figure.

shape Step 5

Click on Save button without entering the Name. Then the message box will appear as shown in the below figure.