Message box in C# window form

 Message Box

In this post we will learn how to use Message box in c# windows form.

First open Visual studio and select Visual C# > Window > Windows Forms Application like below image.

Windows Forms Application

Now click Ok Button and you can like below image type interface.

WIndow Forms Interface

Now click on the toolbox and choose button and change the button text . My button text name is Show Msg Box as you can see like below image.

Change Butotn Text


After complete Above process now double click on the Show Msg Box  and write few code like below image.

Message Box Code

Code :-

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace msgbox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object senderEventArgs e)
        {
            MessageBox.Show("I'm a Message box");
        }
    }
}

After write that code, click on the Start and see output like this:-

OUTPUT
Message Box Output

Comments