You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ide/create-a-visual-basic-winform-in-visual-studio.md
+32-21Lines changed: 32 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "Create a Windows Forms app with Visual Basic"
3
3
description: "Learn how to create a Windows Forms app in Visual Studio with Visual Basic, step-by-step."
4
-
ms.date: 03/23/2019
4
+
ms.date: 09/27/2019
5
5
ms.topic: tutorial
6
6
ms.prod: visual-studio-windows
7
7
ms.technology: vs-ide-general
@@ -10,7 +10,7 @@ author: TerryGLee
10
10
ms.author: tglee
11
11
manager: jillfra
12
12
dev_langs:
13
-
- vb
13
+
- VB
14
14
ms.workload:
15
15
- "multiple"
16
16
---
@@ -41,9 +41,9 @@ First, you'll create a Visual Basic application project. The project type comes
41
41
42
42
1. Open Visual Studio 2017.
43
43
44
-
2. From the top menu bar, choose **File** > **New** > **Project**.
44
+
1. From the top menu bar, choose **File** > **New** > **Project**.
45
45
46
-
3. In the **New Project** dialog box in the left pane, expand **Visual Basic**, and then choose **Windows Desktop**. In the middle pane, choose **Windows Forms App (.NET Framework)**. Then name the file `HelloWorld`.
46
+
1. In the **New Project** dialog box in the left pane, expand **Visual Basic**, and then choose **Windows Desktop**. In the middle pane, choose **Windows Forms App (.NET Framework)**. Then name the file `HelloWorld`.
47
47
48
48
If you don't see the **Windows Forms App (.NET Framework)** project template, cancel out of the **New Project** dialog box and from the top menu bar, choose **Tools** > **Get Tools and Features**. The Visual Studio Installer launches. Choose the **.NET desktop development** workload, then choose **Modify**.
49
49
@@ -59,19 +59,19 @@ First, you'll create a Visual Basic application project. The project type comes
59
59
60
60

61
61
62
-
1. On the **Create a new project** window, enter or type *Windows Forms* in the search box. Next, choose **Visual Basic** from the Language list, and then choose **Windows** from the Platform list.
62
+
1. On the **Create a new project** window, choose the **Windows Forms App (.NET Framework)** template for Visual Basic.
63
63
64
-
After you apply the language and platform filters, choose the **Windows Forms App (.NET Framework)** template, and then choose **Next**.
64
+
(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 **Visual Basic** from the Language list, and then choose **Windows** from the Platform list.)
65
65
66
66

67
67
68
68
> [!NOTE]
69
69
> 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.
70
70
>
71
-
> 
72
-
>
71
+
> 
72
+
>
73
73
> Next, in the Visual Studio Installer, choose the Choose the **.NET desktop development** workload.
74
-
>
74
+
>
75
75
> 
76
76
>
77
77
> 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](#create-a-project)" procedure.
@@ -86,49 +86,52 @@ First, you'll create a Visual Basic application project. The project type comes
86
86
87
87
## Create the application
88
88
89
-
After you select your Visual Basic 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 application.
89
+
After you select your Visual Basic 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.
90
90
91
91
### Add a button to the form
92
92
93
93
1. Click **Toolbox** to open the Toolbox fly-out window.
94
94
95
95

96
96
97
-
(If you don't see the **Toolbox** fly-out option, you can open by pressing**Ctrl**+**Alt**+**X**.)
97
+
(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**.)
98
98
99
-
2. Click the **Pin** icon to dock the **Toolbox** window.
99
+
1. Click the **Pin** icon to dock the **Toolbox** window.
100
100
101
101

102
102
103
-
3. Click the **Button** control and then drag it onto the form.
103
+
1. Click the **Button** control and then drag it onto the form.
104
104
105
105

106
106
107
-
4. In the **Appearance** section (or the **Fonts** section) of the **Properties** window, type `Click this`, and then press **Enter**.
107
+
1. In the **Appearance** section (or the **Fonts** section) of the **Properties** window, type `Click this`, and then press **Enter**.
108
108
109
109

110
110
111
111
(If you don't see the **Properties** window, you can open it from the menu bar. To do so, click **View** > **Properties Window**. Or, press **F4**.)
112
112
113
-
5. In the **Design** section of the **Properties** window, change the name from **Button1** to `btnClickThis`, and then press **Enter**.
113
+
1. In the **Design** section of the **Properties** window, change the name from **Button1** to `btnClickThis`, and then press **Enter**.
114
114
115
115

116
116
117
+
> [!NOTE]
118
+
> If you've alphabetized the list in the **Properties** window, **Button1** appears in the **(DataBindings)** section, instead.
119
+
117
120
### Add a label to the form
118
121
119
122
Now that we've added a button control to create an action, let's add a label control to send text to.
120
123
121
124
1. Select the **Label** control from the **Toolbox** window, and then drag it onto the form and drop it beneath the **Click this** button.
122
125
123
-
2. In the **Design** section of the **Properties** window, change the name from**Label1** to `lblHelloWorld`, and then press **Enter**.
126
+
1. In either the **Design** section or the **(DataBindings)** section of the **Properties** window, change the name of**Label1** to `lblHelloWorld`, and then press **Enter**.
124
127
125
128
### Add code to the form
126
129
127
130
1. In the **Form1.vb [Design]** window, double-click the **Click this** button to open the **Form1.vb** window.
128
131
129
132
(Alternatively, you can expand **Form1.vb** in **Solution Explorer**, and then click **Form1**.)
130
133
131
-
2. In the **Form1.vb** window, between the **Private Sub**line and the **End Sub**line (or between the **Public Class Form1** line and the **End Class** line), type the following code.
134
+
1. In the **Form1.vb** window, between the **Private Sub** and **End Sub**lines, type or enter `lblHelloWorld.Text = "Hello World!"` as shown in the following screenshot:
132
135
133
136

134
137
@@ -140,13 +143,21 @@ Now that we've added a button control to create an action, let's add a label con
140
143
141
144
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**.
142
145
143
-
2. Click the **Click this** button in the **Form1** dialog box. Notice that the **Label1** text changes to **Hello World!**.
146
+
1. Click the **Click this** button in the **Form1** dialog box. Notice that the **Label1** text changes to **Hello World!**.
144
147
145
148

146
149
147
-
Congratulations on completing this quickstart! We hope you learned a little bit about Visual Basic and the Visual Studio IDE. If you'd like to delve deeper, please continue with a tutorial in the **Tutorials** section of the table of contents.
150
+
1. Close the **Form1** dialog box to stop running the app.
151
+
152
+
## Next steps
153
+
154
+
To learn more, continue with the following tutorial:
155
+
156
+
> [!div class="nextstepaction"]
157
+
> [Tutorial: Create a picture viewer](tutorial-1-create-a-picture-viewer.md)
148
158
149
159
## See also
150
160
151
-
*[Quickstart: Create a console app in Visual Studio with Visual Basic](quickstart-visual-basic-console.md)
152
-
*[Learn more about Visual Basic IntelliSense](visual-basic-specific-intellisense.md)
description: "Learn how to create a Windows Forms app in Visual Studio with C#, step-by-step."
4
+
ms.date: 09/26/2019
5
+
ms.topic: tutorial
6
+
ms.prod: visual-studio-windows
7
+
ms.technology: vs-ide-general
8
+
ms.devlang: CSharp
9
+
author: TerryGLee
10
+
ms.author: tglee
11
+
manager: jillfra
12
+
dev_langs:
13
+
- CSharp
14
+
ms.workload:
15
+
- "multiple"
16
+
---
17
+
# Create a Windows Forms app in Visual Studio with C#
18
+
19
+
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).
20
+
21
+
::: moniker range="vs-2017"
22
+
23
+
If you haven't already installed Visual Studio, go to the [Visual Studio downloads](https://visualstudio.microsoft.com/vs/older-downloads/?utm_medium=microsoft&utm_source=docs.microsoft.com&utm_campaign=vs+2017+download) page to install it for free.
24
+
25
+
::: moniker-end
26
+
27
+
::: moniker range="vs-2019"
28
+
29
+
If you haven't already installed Visual Studio, go to the [Visual Studio downloads](https://visualstudio.microsoft.com/downloads) page to install it for free.
30
+
31
+
> [!NOTE]
32
+
> Some of the screenshots in this tutorial use the dark theme. If you aren't using the dark theme but would like to, see the [Personalize the Visual Studio IDE and Editor](../ide/quickstart-personalize-the-ide.md) page to learn how.
33
+
34
+
::: moniker-end
35
+
36
+
## Create a project
37
+
38
+
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.
39
+
40
+
::: moniker range="vs-2017"
41
+
42
+
1. Open Visual Studio 2017.
43
+
44
+
1. From the top menu bar, choose **File** > **New** > **Project**.
45
+
46
+
1. In the **New Project** dialog box in the left pane, expand **Visual C#**, and then choose **Windows Desktop**. In the middle pane, choose **Windows Forms App (.NET Framework)**. Then name the file `HelloWorld`.
47
+
48
+
If you don't see the **Windows Forms App (.NET Framework)** project template, cancel out of the **New Project** dialog box and from the top menu bar, choose **Tools** > **Get Tools and Features**. The Visual Studio Installer launches. Choose the **.NET desktop development** workload, then choose **Modify**.
49
+
50
+

51
+
52
+
::: moniker-end
53
+
54
+
::: moniker range="vs-2019"
55
+
56
+
1. Open Visual Studio 2019.
57
+
58
+
1. On the start window, choose **Create a new project**.
59
+
60
+

61
+
62
+
1. On the **Create a new project** window, choose the **Windows Forms App (.NET Framework)** template for C#.
63
+
64
+
(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.)
65
+
66
+

67
+
68
+
> [!NOTE]
69
+
> 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.
70
+
>
71
+
> 
72
+
>
73
+
> Next, in the Visual Studio Installer, choose the Choose the **.NET desktop development** workload.
74
+
>
75
+
> 
76
+
>
77
+
> 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](#create-a-project)" procedure.
78
+
79
+
1. In the **Configure your new project** window, type or enter *HelloWorld* in the **Project name** box. Then, choose **Create**.
80
+
81
+

82
+
83
+
Visual Studio opens your new project.
84
+
85
+
::: moniker-end
86
+
87
+
## Create the application
88
+
89
+
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.
90
+
91
+
### Add a button to the form
92
+
93
+
1. Choose **Toolbox** to open the Toolbox fly-out window.
94
+
95
+

96
+
97
+
(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**.)
98
+
99
+
1. Choose the **Pin** icon to dock the **Toolbox** window.
100
+
101
+

102
+
103
+
1. Choose the **Button** control and then drag it onto the form.
104
+
105
+

106
+
107
+
1. In the **Properties** window, locate **Text**, change the name from **Button1** to `Click this`, and then press **Enter**.
108
+
109
+

110
+
111
+
(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**.)
112
+
113
+
1. In the **Design** section of the **Properties** window, change the name from **Button1** to `btnClickThis`, and then press **Enter**.
114
+
115
+

116
+
117
+
> [!NOTE]
118
+
> If you've alphabetized the list in the **Properties** window, **Button1** appears in the **(DataBindings)** section, instead.
119
+
120
+
### Add a label to the form
121
+
122
+
Now that we've added a button control to create an action, let's add a label control to send text to.
123
+
124
+
1. Select the **Label** control from the **Toolbox** window, and then drag it onto the form and drop it beneath the **Click this** button.
125
+
126
+
1. In either the **Design** section or the **(DataBindings)** section of the **Properties** window, change the name of **Label1** to `lblHelloWorld`, and then press **Enter**.
127
+
128
+
### Add code to the form
129
+
130
+
1. In the **Form1.cs [Design]** window, double-click the **Click this** button to open the **Form1.cs** window.
131
+
132
+
(Alternatively, you can expand **Form1.cs** in **Solution Explorer**, and then choose **Form1**.)
133
+
134
+
1. In the **Form1.cs** window, after the **private void** line, type or enter `lblHelloWorld.Text = "Hello World!";` as shown in the following screenshot:
135
+
136
+

137
+
138
+
## Run the application
139
+
140
+
1. Choose the **Start** button to run the application.
141
+
142
+

143
+
144
+
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**.
145
+
146
+
1. Choose the **Click this** button in the **Form1** dialog box. Notice that the **Label1** text changes to **Hello World!**.
147
+
148
+

149
+
150
+
1. Close the **Form1** dialog box to stop running the app.
151
+
152
+
## Next steps
153
+
154
+
To learn more, continue with the following tutorial:
155
+
156
+
> [!div class="nextstepaction"]
157
+
> [Tutorial: Create a picture viewer](tutorial-1-create-a-picture-viewer.md)
0 commit comments