Windows form application C# Visual Studio 2022

Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Create a Windows Forms app in Visual Studio with C#

  • Article
  • 09/01/2022
  • 6 minutes to read

In this article

Applies to:

Windows form application C# Visual Studio 2022
Visual Studio
Windows form application C# Visual Studio 2022
Visual Studio for Mac
Windows form application C# Visual Studio 2022
Visual Studio Code

In this short introduction to the Visual Studio integrated development environment (IDE), you'll create a simple C# application that has a Windows-based user interface (UI).

Create a project

First, you'll create a C# application project. The project type comes with all the template files you'll need, before you've even added anything.

  1. Open Visual Studio.

  2. On the start window, choose Create a new project.

    Windows form application C# Visual Studio 2022

  3. On the Create a new project window, choose the Windows Forms App (.NET Framework) template for C#.

    (If you prefer, you can refine your search to quickly get to the template you want. For example, enter or type Windows Forms App in the search box. Next, choose C# from the Language list, and then choose Windows from the Platform list.)

    Windows form application C# Visual Studio 2022

    Note

    If you do not see the Windows Forms App (.NET Framework) template, you can install it from the Create a new project window. In the Not finding what you're looking for? message, choose the Install more tools and features link.

    Windows form application C# Visual Studio 2022

    Next, in the Visual Studio Installer, choose the .NET desktop development workload.

    Windows form application C# Visual Studio 2022

    After that, choose the Modify button in the Visual Studio Installer. You might be prompted to save your work; if so, do so. Next, choose Continue to install the workload. Then, return to step 2 in this "Create a project" procedure.

  4. In the Configure your new project window, type or enter HelloWorld in the Project name box. Then, choose Create.

    Windows form application C# Visual Studio 2022

    Visual Studio opens your new project.

  1. Open Visual Studio.

  2. On the start window, select Create a new project.

    Windows form application C# Visual Studio 2022

  3. On the Create a new project window, select the Windows Forms App (.NET Framework) template for C#.

    (If you prefer, you can refine your search to quickly get to the template you want. For example, enter or type Windows Forms App in the search box. Next, select C# from the Language list, and then select Windows from the Platform list.)

    Windows form application C# Visual Studio 2022

    Note

    If you do not see the Windows Forms App (.NET Framework) template, you can install it from the Create a new project window. In the Not finding what you're looking for? message, select the Install more tools and features link.

    Windows form application C# Visual Studio 2022

    Next, in the Visual Studio Installer, select the .NET desktop development workload.

    Windows form application C# Visual Studio 2022

    After that, select the Modify button in the Visual Studio Installer. You might be prompted to save your work; if so, do so. Next, select Continue to install the workload. Then, return to step 2 in this "Create a project" procedure.

  4. In the Configure your new project window, type or enter HelloWorld in the Project name box. Then, select Create.

    Windows form application C# Visual Studio 2022

    Visual Studio opens your new project.

Create the application

After you select your C# project template and name your file, Visual Studio opens a form for you. A form is a Windows user interface. We'll create a "Hello World" application by adding controls to the form, and then we'll run the app.

Add a button to the form

  1. Select Toolbox to open the Toolbox fly-out window.

    Windows form application C# Visual Studio 2022

    (If you don't see the Toolbox fly-out option, you can open it from the menu bar. To do so, View > Toolbox. Or, press Ctrl+Alt+X.)

  2. Select the Pin icon to dock the Toolbox window.

    Windows form application C# Visual Studio 2022

  3. Select the Button control and then drag it onto the form.

    Windows form application C# Visual Studio 2022

  4. In the Properties window, locate Text, change the name from button1 to Click this, and then press Enter.

    Windows form application C# Visual Studio 2022

    (If you don't see the Properties window, you can open it from the menu bar. To do so, select View > Properties Window. Or, press F4.)

  5. In the Design section of the Properties window, change the name from button1 to btnClickThis, and then press Enter.

    Windows form application C# Visual Studio 2022

    Note

    If you've alphabetized the list in the Properties window, button1 appears in the (DataBindings) section, instead.

Add a label to the form

Now that we've added a button control to create an action, let's add a label control to send text to.

  1. Select the Label control from the Toolbox window, and then drag it onto the form and drop it beneath the Click this button.

  2. In either the Design section or the (DataBindings) section of the Properties window, change the name of label1 to lblHelloWorld, and then press Enter.

Add code to the form

  1. In the Form1.cs [Design] window, double-click the Click this button to open the Form1.cs window.

    (Alternatively, you can expand Form1.cs in Solution Explorer, and then choose Form1.)

  2. In the Form1.cs window, after the private void line, type or enter lblHelloWorld.Text = "Hello World!"; as shown in the following screenshot:

    Windows form application C# Visual Studio 2022

Run the application

  1. Select the Start button to run the application.

    Windows form application C# Visual Studio 2022

    Several things will happen. In the Visual Studio IDE, the Diagnostics Tools window will open, and an Output window will open, too. But outside of the IDE, a Form1 dialog box appears. It will include your Click this button and text that says label1.

  2. Select the Click this button in the Form1 dialog box. Notice that the label1 text changes to Hello World!.

    Windows form application C# Visual Studio 2022

  3. Close the Form1 dialog box to stop running the app.

Create the application

After you select your C# project template and name your file, Visual Studio opens a form for you. A form is a Windows user interface. We'll create a "Hello World" application by adding controls to the form, and then we'll run the app.

Add a button to the form

  1. Choose Toolbox to open the Toolbox fly-out window.

    Windows form application C# Visual Studio 2022

    (If you don't see the Toolbox fly-out option, you can open it from the menu bar. To do so, View > Toolbox. Or, press Ctrl+Alt+X.)

  2. Choose the Pin icon to dock the Toolbox window.

    Windows form application C# Visual Studio 2022

  3. Choose the Button control and then drag it onto the form.

    Windows form application C# Visual Studio 2022

  4. In the Properties window, locate Text, change the name from Button1 to Click this, and then press Enter.

    Windows form application C# Visual Studio 2022

    (If you don't see the Properties window, you can open it from the menu bar. To do so, choose View > Properties Window. Or, press F4.)

  5. In the Design section of the Properties window, change the name from Button1 to btnClickThis, and then press Enter.

    Windows form application C# Visual Studio 2022

    Note

    If you've alphabetized the list in the Properties window, Button1 appears in the (DataBindings) section, instead.

Add a label to the form

Now that we've added a button control to create an action, let's add a label control to send text to.

  1. Select the Label control from the Toolbox window, and then drag it onto the form and drop it beneath the Click this button.

  2. In either the Design section or the (DataBindings) section of the Properties window, change the name of Label1 to lblHelloWorld, and then press Enter.

Add code to the form

  1. In the Form1.cs [Design] window, double-click the Click this button to open the Form1.cs window.

    (Alternatively, you can expand Form1.cs in Solution Explorer, and then choose Form1.)

  2. In the Form1.cs window, after the private void line, type or enter lblHelloWorld.Text = "Hello World!"; as shown in the following screenshot:

    Windows form application C# Visual Studio 2022

Run the application

  1. Choose the Start button to run the application.

    Windows form application C# Visual Studio 2022

    Several things will happen. In the Visual Studio IDE, the Diagnostics Tools window will open, and an Output window will open, too. But outside of the IDE, a Form1 dialog box appears. It will include your Click this button and text that says Label1.

  2. Choose the Click this button in the Form1 dialog box. Notice that the Label1 text changes to Hello World!.

    Windows form application C# Visual Studio 2022

  3. Close the Form1 dialog box to stop running the app.

Next steps

To learn more, continue with the following tutorial:

See also

  • More C# tutorials
  • Visual Basic tutorials
  • C++ tutorials

Feedback

Submit and view feedback for

What is Windows form application in C#?

A Windows form in C# application is one that runs on the desktop of a computer. Visual Studio Form along with C# can be used to create a Windows Forms application. Controls can be added to the Windows forms C# via the Toolbox in Visual Studio. Controls such as labels, checkboxes, radio buttons, etc.

Is WinForms better than WPF?

Winforms vs WPF both are mainly used for the same purpose for developing and designing windows applications, but WPF can be used for the web application. The difference between them is scalability, performance as WPF can render fast compared to windows forms, complexity, and support.

Is WinForms still used in 2022?

Now, in 2022, with increasing competition and the adoption of newer more modern technologies the popularity and usage of WinForms are at an all-time low.

Is WinForms going away?

Win Form has been used to develop many applications. Because of its high age (born in 2003), WinForm was officially declared dead by Microsoft in 2014.