Hello World Windows Forms Application using C#

by Jagadish Pulakhandam on 4/9/2011 6:45:32 PM
Rated 0 from 0 votes
Brief: This article is for the very beginner who wants to learn and program C# for the first time using Windows Forms.
Posted to: Microsoft Windows Forms - Basics
Add to DiggAdd to del.icio.usAdd to FURLAdd to RedditAdd to YahooAdd to BlinklistAdd to GoogleAdd to ma.gnoliaAdd to ShadowsAdd to Technorati

This article assumes that you have Microsoft Visual Studio 2010 installed on your system.  Following are the steps to create your first Windows Forms application using C#:
  • Go to Start || Programs || Microsoft Visual Studio 2010 || Microsoft Visual Studio 2010
  • Once 'Microsoft Visual Studio 2010" is opened, go to "File" menu and select "New Project"

  • In the "New Project" dialog, select "Visual C# || Windows" (from installed templates), select "Windows Forms Application" from right pane, provide "Name" as "SampleFormsApplication" and finally click on "Ok".
  • You should have "Form1.cs" created and opened (nothing but Windows Form).  Drag "Button" control from "Toolbox" and drop it on to canvas as shown below:

  • Make sure that button is selected (by clicking on it once), open its properties (F4) and modify the property values as shown below:




  • Now your form should look as shown below:


  • Using "Properties" window, open events, type "btnMsg_click" in "Click" event and press enter as shown below (another short cut is to just double click on button on the form or double click on the event name in properties window):


  • Modify the code as shown below:
01.using System;
02.using System.Collections.Generic;
03.using System.ComponentModel;
04.using System.Data;
05.using System.Drawing;
06.using System.Linq;
07.using System.Text;
08.using System.Windows.Forms;
09. 
10.namespace SampleFormsApplication
11.{
12.    public partial class Form1 : Form
13.    {
14.        public Form1()
15.        {
16.            InitializeComponent();
17.        }
18. 
19.        private void btnMsg_Click(object sender, EventArgs e)
20.        {
21.            MessageBox.Show("Hello World!");
22.        }
23.    }
24.}
  • Press F5 and click on the button "Show Msg.".  It should give you the output as shown below:

Join the .NET Code Central Community and join the discussion!
Signing-up is FREE and quick. Do it now, we want to hear your opinion
0

Rated 0 from 0 votes ( login  to rate)
DotnetKicks DotnetKicksDe DotNetShoutout

Attachments / Source Code
You need to Login or Join for FREE to download the following