Visual Studio is an extremely powerful IDE for building many types of applications.
In this how-to, we are going to build a “Hello World” Windows forms application in C#.
Ok, let’s build our Hello World app!
In this example I’m using Visual Studio 2013 and .NET Framework 4.5 but the philosophy is the same for newer versions of Visual Studio and .NET Framework.
So, after launching Visual Studio, we click on “File“, “New“, “Project“.
We then select the template for this new project, in this case “Windows Desktop” (1), the version of .NET Framework to be used (2), the type of the project, in this case “Windows Forms Application” (3), the name and disk location of the project (4 and 5), and finally the solution name (6) which by default gets the same name as the project name but of course you can change it if you want. After all these are set, we click on the “OK” button.
Right after we click OK, the new project is ready for development. The below screenshot illustrates the development environment for this Windows Forms project.
The next step is to drag and drop a “button” control from the toolbox right onto our form (named Form1 – you can change the name in the Properties dialog on the lower right section of the IDE).
Right after we add the button, we set the two below properties in the Properties dialog which can be found on the lower right section of the IDE):
- Name: btnClickMe
- Text: Click Me!
Now we need to set the button’s behavior when clicked. We double-click on the button control on the form and an “event handler” for the mouse click event on the button is automatically created. Now all is left is to add to the event handler the code we want to be executed when the button is clicked. To this end, we add the code: MessageBox.Show(“Hello World! This is a C# program!”);
Right after adding the code, we press F5 or click on the Start button (has the “play” sign) and if everything is OK, our program runs.
So let’s test our program by clicking on the “Click Me!” button:
That’s it! As you can see, when we click the button a popup (message box) is presented displaying the “Hello World” message!
Reference: TechHowTos.com (http://www.techhowtos.com)
Rate this article:
Recommended eBooks on SQL Server: