Introduction
Form applications are run on Windows desktop computers. They contain a collection of controls, such as textboxes, listboxes and labels etc. In order to learn about complete form applications, it is important to learn the basic steps.
This article is an introduction to form applications with simple steps to implement a simple "Hello World" application in Visual Studio 2017.
Step 1 - Open Visual Studio
Once Visual Studio is launched, in the menu option, choose a new project (New-->new project) and after that choose Visual C# and Windows Form application. Location, Solution, Solution Name, and Framework are to be kept the default. The name of the project can be given as you like. Click Ok to start the project.
Step 2 - Toolbox and Solution Explorer
Now, the form designer page is open. Toolbox is on the left side of the form. If it is not visible, click the view option and choose Toolbox. In the Toolbox, choose common controls. It contains labels, textboxes, and buttons etc. And on the right side of the project, in the solution explorer, the properties of the forms and the object can be inserted or altered.
STEP 3 - Designer Page
At first, form desiger will be loaded in Visual Studio. In this form designer, you can start building your Windows Form application. Add Button from Toolbox to the designer page.
To declare and to use the button in the form application,
- Declare a button control
- In the constructor, create the button and set its size, location and text properties.
- Add Button to the Form
Changing the Text and Name of the button in the properties window is important for applications using multiple Buttons. But here, we are going to display a message with a single button so it is not an important task.
Step 4 - Coding for Button Click
Now, double-click the button and the main page for coding is displayed. Use messagebox.show and the the contents to be displayed.
messagebox.show is used for the purpose of displaying a message with specified text.
- 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 WindowsFormsApp1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
-
- private void button2_Click(object sender, EventArgs e)
- {
- MessageBox.Show("Hello World");
- }
- }
- }
Step 5 - Compile and RunAfter saving , now compile and run the application by means of the debug icon or press F5.
Step 6 - Output of the ProjectNow, the simple Form application is ready. By clicking the button the message box is displayed and it shows the result as
" Hello World".
Summary
In Visual Studio 2017, the simple "Hello World " application is created by using the button. It is the form application we can use for displaying the message.