Basic Steps To Construct Form Application Using Visual Studio 2017

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. 

Visual Studio
 
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.

Visual Studio
 
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,
  1. Declare a button control
  2. In the constructor, create the button and set its size, location and text properties.
  3. 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.

Visual Studio
 
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. 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Threading.Tasks;  
  9. using System.Windows.Forms;  
  10.   
  11. namespace WindowsFormsApp1  
  12. {  
  13.     public partial class Form1 : Form  
  14.     {  
  15.         public Form1()  
  16.         {  
  17.             InitializeComponent();  
  18.         }  
  19.   
  20.         private void button2_Click(object sender, EventArgs e)  
  21.         {  
  22.             MessageBox.Show("Hello World");  
  23.         }  
  24.     }  
  25. }  
Visual Studio 
 
Step 5 - Compile and Run

After saving , now compile and run the application by means of the debug icon or press F5. 

Visual Studio 

Step 6 - Output of the Project

Now, 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. 


Similar Articles