diff --git a/dotnet-desktop-guide/index.yml b/dotnet-desktop-guide/index.yml index 95e03bfa9b..5e1e0b7995 100644 --- a/dotnet-desktop-guide/index.yml +++ b/dotnet-desktop-guide/index.yml @@ -10,20 +10,20 @@ metadata: ms.product: dotnet author: adegeo ms.author: adegeo - ms.date: 10/21/2020 + ms.date: 11/15/2021 # linkListType: architecture | concept | deploy | download | get-started | how-to-guide | learn | overview | quickstart | reference | sample | tutorial | video | whats-new landingContent: -- title: .NET 5 (and .NET Core 3.1) +- title: .NET 5+ (and .NET Core 3.1) linkLists: - linkListType: overview links: - text: Windows Presentation Foundation (WPF) - url: net/wpf/index.yml?view=netdesktop-5.0&preserve-view=true + url: net/wpf/index.yml?view=netdesktop-6.0&preserve-view=true - text: Windows Forms (WinForms) - url: net/winforms/index.yml?view=netdesktop-5.0&preserve-view=true + url: net/winforms/index.yml?view=netdesktop-6.0&preserve-view=true - title: .NET Framework linkLists: diff --git a/dotnet-desktop-guide/net/winforms/get-started/create-app-visual-studio.md b/dotnet-desktop-guide/net/winforms/get-started/create-app-visual-studio.md index cf4735e4c2..027d577074 100644 --- a/dotnet-desktop-guide/net/winforms/get-started/create-app-visual-studio.md +++ b/dotnet-desktop-guide/net/winforms/get-started/create-app-visual-studio.md @@ -1,16 +1,16 @@ --- title: "Create a new app with Visual Studio tutorial" description: Follow this tutorial to learn how to create a new Windows Forms app for .NET with Visual Studio 2019. -ms.date: 10/26/2020 +ms.date: 11/15/2021 ms.topic: tutorial dev_langs: - "csharp" - "vb" --- -# Tutorial: Create a new WinForms app (Windows Forms .NET) +# Tutorial: Create a Windows Forms app with .NET -In this short tutorial, you'll learn how to create a new Windows Forms (WinForms) app with Visual Studio. Once the initial app has been generated, you'll learn how to add controls and how to handle events. By the end of this tutorial, you'll have a simple app that adds names to a list box. +In this short tutorial, you'll learn how to create a new Windows Forms app with Visual Studio. Once the initial app has been generated, you'll learn how to add controls and how to handle events. By the end of this tutorial, you'll have a simple app that adds names to a list box. [!INCLUDE [desktop guide under construction](../../includes/desktop-guide-preview-note.md)] @@ -18,25 +18,39 @@ In this tutorial, you learn how to: > [!div class="checklist"] > -> - Create a new WinForms app +> - Create a new Windows Forms app > - Add controls to a form > - Handle control events to provide app functionality > - Run the app ## Prerequisites +:::moniker range="netdesktop-5.0" + - [Visual Studio 2019 version 16.8 or later versions](https://visualstudio.microsoft.com/downloads/?utm_medium=microsoft&utm_source=docs.microsoft.com&utm_campaign=inline+link&utm_content=download+vs2019+desktopguide+winforms) - Select the [Visual Studio Desktop workload](/visualstudio/install/modify-visual-studio?view=vs-2019&preserve-view=true#modify-workloads) - Select the [.NET 5 individual component](/visualstudio/install/modify-visual-studio?view=vs-2019&preserve-view=true#modify-individual-components) -## Create a WinForms app +:::moniker-end + +:::moniker range="netdesktop-6.0" + +- [Visual Studio 2022 version 17.0 or later versions](https://visualstudio.microsoft.com/downloads/?utm_medium=microsoft&utm_source=docs.microsoft.com&utm_campaign=inline+link&0utm_content=download+vs2022+desktopguide+winforms) + - Select the [.NET desktop development workload](/visualstudio/install/modify-visual-studio?view=vs-2019&preserve-view=true#modify-workloads) + - Select the [.NET 6 individual component](/visualstudio/install/modify-visual-studio?view=vs-2019&preserve-view=true#modify-individual-components) + +:::moniker-end + +## Create a Windows Forms app The first step to creating a new app is opening Visual Studio and generating the app from a template. +:::moniker range="netdesktop-5.0" + 01. Open Visual Studio. 01. Select **Create a new project**. - :::image type="content" source="media/create-app-visual-studio/vs-create-new-project.png" alt-text="Create a new Windows Forms project in Visual Studio 2019 for .NET"::: + :::image type="content" source="media/create-app-visual-studio/netdesktop-5.0/vs-create-new-project.png" alt-text="Create a new Windows Forms project in Visual Studio 2019 for .NET"::: 01. In the **Search for templates** box, type **winforms**, and then press Enter. 01. In the **code language** dropdown, choose **C#** or **Visual Basic**. @@ -45,25 +59,67 @@ The first step to creating a new app is opening Visual Studio and generating the > [!IMPORTANT] > Don't select the **Windows Forms App (.NET _Framework_)** template. - :::image type="content" source="media/create-app-visual-studio/vs-template-search.png" alt-text="Search for the Windows Forms template in Visual Studio 2019 for .NET"::: + :::image type="content" source="media/create-app-visual-studio/netdesktop-5.0/vs-template-search.png" alt-text="Search for the Windows Forms template in Visual Studio 2019 for .NET"::: 01. In the **Configure your new project** window, set the **Project name** to **Names** and click **Create**. You can also save your project to a different folder by adjusting the **Location** setting. - :::image type="content" source="media/create-app-visual-studio/vs-config-new-project.png" alt-text="Configure new Windows Forms project in Visual Studio 2019 for .NET"::: + :::image type="content" source="media/create-app-visual-studio/netdesktop-5.0/vs-config-new-project.png" alt-text="Configure new Windows Forms project in Visual Studio 2019 for .NET"::: + +:::moniker-end + +:::moniker range="netdesktop-6.0" + +01. Open Visual Studio. +01. Select **Create a new project**. + + :::image type="content" source="media/create-app-visual-studio/netdesktop-6.0/vs-create-new-project.png" alt-text="Create a new Windows Forms project in Visual Studio 2022 for .NET."::: + +01. In the **Search for templates** box, type **winforms**, and wait for the search results to appear. +01. In the **code language** dropdown, choose **C#** or **Visual Basic**. +01. In the list of templates, select **Windows Forms App** and then click **Next**. + + > [!IMPORTANT] + > Don't select the **Windows Forms App (.NET _Framework_)** template. + + The following image shows both C# and Visual Basic .NET project templates. If you applied the **code language** filter, you'll see the corresponding template. + + :::image type="content" source="media/create-app-visual-studio/netdesktop-6.0/vs-template-search.png" alt-text="Search for the Windows Forms template in Visual Studio 2022 for .NET"::: + +01. In the **Configure your new project** window, set the **Project name** to _Names_ and click **Next**. + + You can also save your project to a different folder by adjusting the **Location** path. + + :::image type="content" source="media/create-app-visual-studio/netdesktop-6.0/vs-config-new-project.png" alt-text="Configure new Windows Forms project in Visual Studio 2022 for .NET"::: + +01. Finally, in the **Additional information** window, select **.NET 6.0 (Long-term support)** for the **Framework** setting, and then click **Create**. + + :::image type="content" source="media/create-app-visual-studio/netdesktop-6.0/vs-select-framework.png" alt-text="Select the target framework for a Windows Forms project in Visual Studio 2022"::: + +:::moniker-end Once the app is generated, Visual Studio should open the designer pane for the default form, _Form1_. If the form designer isn't visible, double-click on the form in the **Solution Explorer** pane to open the designer window. ### Important parts of Visual Studio -Support for WinForms in Visual Studio has four important components that you'll interact with as you create an app: +Support for Windows Forms in Visual Studio has four important components that you'll interact with as you create an app: -:::image type="content" source="media/create-app-visual-studio/vs-main-window.png" alt-text="The important components of Visual Studio you should know when creating a Windows Forms project for .NET"::: +:::moniker range="netdesktop-5.0" + +:::image type="content" source="media/create-app-visual-studio/netdesktop-5.0/vs-main-window.png" alt-text="The important components of Visual Studio 2019 you should know when creating a Windows Forms project for .NET"::: + +:::moniker-end + +:::moniker range="netdesktop-6.0" + +:::image type="content" source="media/create-app-visual-studio/netdesktop-6.0/vs-main-window.png" alt-text="The important components of Visual Studio 2022 you should know when creating a Windows Forms project for .NET"::: + +:::moniker-end 01. Solution Explorer - All if your project files, code, forms, resources, will appear in this pane. + All of your project files, code, forms, resources, will appear in this pane. 02. Properties @@ -111,7 +167,17 @@ You can position and size the controls according to the following settings. Eith You should have a form in the designer that looks similar to the following: -:::image type="content" source="media/create-app-visual-studio/vs-form-preview.png" alt-text="Visual Studio 2019 designer with the form open for Windows Forms for .NET"::: +:::moniker range="netdesktop-5.0" + +:::image type="content" source="media/create-app-visual-studio/netdesktop-5.0/vs-form-preview.png" alt-text="Visual Studio 2019 designer with the form open for Windows Forms for .NET"::: + +:::moniker-end + +:::moniker range="netdesktop-6.0" + +:::image type="content" source="media/create-app-visual-studio/netdesktop-6.0/vs-form-preview.png" alt-text="Visual Studio 2022 designer with the form open for Windows Forms for .NET"::: + +:::moniker-end ## Handle events @@ -140,27 +206,25 @@ Now that the form has all of its controls laid out, you need to handle the event 01. The following code demonstrates adding a name to the `lstNames` control: - ```csharp - private void btnAdd_Click(object sender, EventArgs e) - { - if (!string.IsNullOrWhiteSpace(txtName.Text) && !lstNames.Items.Contains(txtName.Text)) - lstNames.Items.Add(txtName.Text); - } - ``` + :::code language="csharp" source="snippets/create-app-visual-studio/csharp/Form1.cs" id="buttonClick"::: - ```vb - Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click - If Not String.IsNullOrWhiteSpace(txtName.Text) And Not lstNames.Items.Contains(txtName.Text) Then - lstNames.Items.Add(txtName.Text) - End If - End Sub - ``` + :::code language="vb" source="snippets/create-app-visual-studio/vb/Form1.vb" id="buttonClick"::: ## Run the app Now that the event has been coded, you can run the app by pressing the F5 key or by selecting **Debug** > **Start Debugging** from the menu. The form displays and you can enter a name in the textbox and then add it by clicking the button. -:::image type="content" source="media/create-app-visual-studio/app-running.png" alt-text="Running a Windows Forms for .NET app."::: +:::moniker range="netdesktop-5.0" + +:::image type="content" source="media/create-app-visual-studio/netdesktop-5.0/app-running.png" alt-text="Running a Windows Forms for .NET app in Visual Studio 2019."::: + +:::moniker-end + +:::moniker range="netdesktop-6.0" + +:::image type="content" source="media/create-app-visual-studio/netdesktop-6.0/app-running.png" alt-text="Running a Windows Forms for .NET app in Visual Studio 2022."::: + +:::moniker-end ## Next steps diff --git a/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/app-running.png b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/app-running.png similarity index 100% rename from dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/app-running.png rename to dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/app-running.png diff --git a/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/vs-config-new-project.png b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/vs-config-new-project.png similarity index 100% rename from dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/vs-config-new-project.png rename to dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/vs-config-new-project.png diff --git a/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/vs-create-new-project.png b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/vs-create-new-project.png similarity index 100% rename from dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/vs-create-new-project.png rename to dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/vs-create-new-project.png diff --git a/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/vs-form-preview.png b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/vs-form-preview.png similarity index 100% rename from dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/vs-form-preview.png rename to dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/vs-form-preview.png diff --git a/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/vs-main-window.pdn b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/vs-main-window.pdn similarity index 100% rename from dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/vs-main-window.pdn rename to dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/vs-main-window.pdn diff --git a/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/vs-main-window.png b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/vs-main-window.png similarity index 100% rename from dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/vs-main-window.png rename to dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/vs-main-window.png diff --git a/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/vs-properties-events.png b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/vs-properties-events.png similarity index 100% rename from dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/vs-properties-events.png rename to dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/vs-properties-events.png diff --git a/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/vs-solution-explorer-form.png b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/vs-solution-explorer-form.png similarity index 100% rename from dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/vs-solution-explorer-form.png rename to dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/vs-solution-explorer-form.png diff --git a/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/vs-template-search-cs.png b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/vs-template-search-cs.png similarity index 100% rename from dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/vs-template-search-cs.png rename to dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/vs-template-search-cs.png diff --git a/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/vs-template-search-vb.png b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/vs-template-search-vb.png similarity index 100% rename from dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/vs-template-search-vb.png rename to dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/vs-template-search-vb.png diff --git a/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/vs-template-search.png b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/vs-template-search.png similarity index 100% rename from dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/vs-template-search.png rename to dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-5.0/vs-template-search.png diff --git a/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/app-running.png b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/app-running.png new file mode 100644 index 0000000000..8367cc23f2 Binary files /dev/null and b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/app-running.png differ diff --git a/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-config-new-project.png b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-config-new-project.png new file mode 100644 index 0000000000..690eb26c2a Binary files /dev/null and b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-config-new-project.png differ diff --git a/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-create-new-project.png b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-create-new-project.png new file mode 100644 index 0000000000..5ef6073412 Binary files /dev/null and b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-create-new-project.png differ diff --git a/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-form-preview.png b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-form-preview.png new file mode 100644 index 0000000000..630fe57e65 Binary files /dev/null and b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-form-preview.png differ diff --git a/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-main-window.pdn b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-main-window.pdn new file mode 100644 index 0000000000..f04b7f591b Binary files /dev/null and b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-main-window.pdn differ diff --git a/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-main-window.png b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-main-window.png new file mode 100644 index 0000000000..702db7519f Binary files /dev/null and b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-main-window.png differ diff --git a/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-select-framework.png b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-select-framework.png new file mode 100644 index 0000000000..cc5a2e3f36 Binary files /dev/null and b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-select-framework.png differ diff --git a/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-template-search.png b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-template-search.png new file mode 100644 index 0000000000..5b1e8497e7 Binary files /dev/null and b/dotnet-desktop-guide/net/winforms/get-started/media/create-app-visual-studio/netdesktop-6.0/vs-template-search.png differ diff --git a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Main.Designer.cs b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Form1.Designer.cs similarity index 87% rename from dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Main.Designer.cs rename to dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Form1.Designer.cs index 8dce82c2d7..fcad6afc16 100644 --- a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Main.Designer.cs +++ b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Form1.Designer.cs @@ -1,4 +1,4 @@ -namespace project +namespace Names { partial class Form1 { @@ -30,8 +30,8 @@ private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.lstNames = new System.Windows.Forms.ListBox(); - this.btnAdd = new System.Windows.Forms.Button(); this.txtName = new System.Windows.Forms.TextBox(); + this.btnAdd = new System.Windows.Forms.Button(); this.SuspendLayout(); // // label1 @@ -52,36 +52,34 @@ private void InitializeComponent() this.lstNames.Size = new System.Drawing.Size(120, 94); this.lstNames.TabIndex = 1; // + // txtName + // + this.txtName.Location = new System.Drawing.Point(138, 26); + this.txtName.Name = "txtName"; + this.txtName.Size = new System.Drawing.Size(100, 23); + this.txtName.TabIndex = 2; + // // btnAdd // this.btnAdd.Location = new System.Drawing.Point(138, 55); this.btnAdd.Name = "btnAdd"; this.btnAdd.Size = new System.Drawing.Size(100, 23); - this.btnAdd.TabIndex = 2; + this.btnAdd.TabIndex = 3; this.btnAdd.Text = "Add Name"; this.btnAdd.UseVisualStyleBackColor = true; this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click); // - // txtName - // - this.txtName.Location = new System.Drawing.Point(138, 26); - this.txtName.Name = "txtName"; - this.txtName.Size = new System.Drawing.Size(100, 23); - this.txtName.TabIndex = 3; - // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(252, 141); - this.Controls.Add(this.txtName); this.Controls.Add(this.btnAdd); + this.Controls.Add(this.txtName); this.Controls.Add(this.lstNames); this.Controls.Add(this.label1); - this.Cursor = System.Windows.Forms.Cursors.Default; this.Name = "Form1"; this.Text = "Names"; - this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); this.PerformLayout(); @@ -89,10 +87,9 @@ private void InitializeComponent() #endregion - private System.Windows.Forms.Label label1; - private System.Windows.Forms.ListBox lstNames; - private System.Windows.Forms.Button btnAdd; - private System.Windows.Forms.TextBox txtName; + private Label label1; + private ListBox lstNames; + private TextBox txtName; + private Button btnAdd; } -} - +} \ No newline at end of file diff --git a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Form1.cs b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Form1.cs new file mode 100644 index 0000000000..8d9682ca0b --- /dev/null +++ b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Form1.cs @@ -0,0 +1,18 @@ +namespace Names +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + // + private void btnAdd_Click(object sender, EventArgs e) + { + if (!string.IsNullOrWhiteSpace(txtName.Text) && !lstNames.Items.Contains(txtName.Text)) + lstNames.Items.Add(txtName.Text); + } + // + } +} \ No newline at end of file diff --git a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Main.resx b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Form1.resx similarity index 100% rename from dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Main.resx rename to dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Form1.resx diff --git a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Main.cs b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Main.cs deleted file mode 100644 index 9b22c60906..0000000000 --- a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Main.cs +++ /dev/null @@ -1,33 +0,0 @@ -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; -using System.Runtime.InteropServices; - -namespace project -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - - private void Form1_Load(object sender, EventArgs e) - { - - } - - private void btnAdd_Click(object sender, EventArgs e) - { - if (!string.IsNullOrWhiteSpace(txtName.Text) && !lstNames.Items.Contains(txtName.Text)) - lstNames.Items.Add(txtName.Text); - } - - } -} diff --git a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/project.csproj b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Names.csproj similarity index 56% rename from dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/project.csproj rename to dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Names.csproj index aa90722ac3..b57c89e694 100644 --- a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/project.csproj +++ b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Names.csproj @@ -2,12 +2,10 @@ WinExe - net5.0-windows + net6.0-windows + enable true + enable - - - - \ No newline at end of file diff --git a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Program.cs b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Program.cs index 07516585b7..ad73690bf1 100644 --- a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Program.cs +++ b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/csharp/Program.cs @@ -1,12 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace project +namespace Names { - static class Program + internal static class Program { /// /// The main entry point for the application. @@ -14,10 +8,8 @@ static class Program [STAThread] static void Main() { - Application.SetHighDpiMode(HighDpiMode.SystemAware); - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); + ApplicationConfiguration.Initialize(); Application.Run(new Form1()); } } -} +} \ No newline at end of file diff --git a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/ApplicationEvents.vb b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/ApplicationEvents.vb new file mode 100644 index 0000000000..cf403a009a --- /dev/null +++ b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/ApplicationEvents.vb @@ -0,0 +1,29 @@ +Imports Microsoft.VisualBasic.ApplicationServices + +Namespace My + ' The following events are available for MyApplication: + ' Startup: Raised when the application starts, before the startup form is created. + ' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally. + ' UnhandledException: Raised if the application encounters an unhandled exception. + ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. + ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected. + + ' **NEW** ApplyApplicationDefaults: Raised when the application queries default values to be set for the application. + + ' Example: + ' Private Sub MyApplication_ApplyApplicationDefaults(sender As Object, e As ApplyApplicationDefaultsEventArgs) Handles Me.ApplyApplicationDefaults + ' + ' ' Setting the application-wide default Font: + ' e.Font = New Font(FontFamily.GenericSansSerif, 12, FontStyle.Regular) + ' + ' ' Setting the HighDpiMode for the Application: + ' e.HighDpiMode = HighDpiMode.PerMonitorV2 + ' + ' ' If a splash dialog is used, this sets the minimum display time: + ' e.MinimumSplashScreenDisplayTime = 4000 + ' End Sub + + Partial Friend Class MyApplication + + End Class +End Namespace diff --git a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/Main.Designer.vb b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/Form1.Designer.vb similarity index 77% rename from dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/Main.Designer.vb rename to dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/Form1.Designer.vb index cf8dde7d5f..0d0a0f70e6 100644 --- a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/Main.Designer.vb +++ b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/Form1.Designer.vb @@ -22,20 +22,27 @@ Partial Class Form1 'Do not modify it using the code editor. Private Sub InitializeComponent() - Me.Label1 = New System.Windows.Forms.Label() - Me.lstNames = New System.Windows.Forms.ListBox() - Me.txtName = New System.Windows.Forms.TextBox() Me.btnAdd = New System.Windows.Forms.Button() + Me.txtName = New System.Windows.Forms.TextBox() + Me.lstNames = New System.Windows.Forms.ListBox() + Me.label1 = New System.Windows.Forms.Label() Me.SuspendLayout() ' - 'Label1 + 'btnAdd + ' + Me.btnAdd.Location = New System.Drawing.Point(138, 55) + Me.btnAdd.Name = "btnAdd" + Me.btnAdd.Size = New System.Drawing.Size(100, 23) + Me.btnAdd.TabIndex = 7 + Me.btnAdd.Text = "Add Name" + Me.btnAdd.UseVisualStyleBackColor = True + ' + 'txtName ' - Me.Label1.AutoSize = True - Me.Label1.Location = New System.Drawing.Point(12, 9) - Me.Label1.Name = "Label1" - Me.Label1.Size = New System.Drawing.Size(44, 15) - Me.Label1.TabIndex = 0 - Me.Label1.Text = "Names" + Me.txtName.Location = New System.Drawing.Point(138, 26) + Me.txtName.Name = "txtName" + Me.txtName.Size = New System.Drawing.Size(100, 23) + Me.txtName.TabIndex = 6 ' 'lstNames ' @@ -44,23 +51,16 @@ Partial Class Form1 Me.lstNames.Location = New System.Drawing.Point(12, 27) Me.lstNames.Name = "lstNames" Me.lstNames.Size = New System.Drawing.Size(120, 94) - Me.lstNames.TabIndex = 1 - ' - 'txtName - ' - Me.txtName.Location = New System.Drawing.Point(138, 26) - Me.txtName.Name = "txtName" - Me.txtName.Size = New System.Drawing.Size(100, 23) - Me.txtName.TabIndex = 2 + Me.lstNames.TabIndex = 5 ' - 'btnAdd + 'label1 ' - Me.btnAdd.Location = New System.Drawing.Point(138, 55) - Me.btnAdd.Name = "btnAdd" - Me.btnAdd.Size = New System.Drawing.Size(100, 23) - Me.btnAdd.TabIndex = 3 - Me.btnAdd.Text = "Add Name" - Me.btnAdd.UseVisualStyleBackColor = True + Me.label1.AutoSize = True + Me.label1.Location = New System.Drawing.Point(12, 9) + Me.label1.Name = "label1" + Me.label1.Size = New System.Drawing.Size(44, 15) + Me.label1.TabIndex = 4 + Me.label1.Text = "Names" ' 'Form1 ' @@ -70,7 +70,7 @@ Partial Class Form1 Me.Controls.Add(Me.btnAdd) Me.Controls.Add(Me.txtName) Me.Controls.Add(Me.lstNames) - Me.Controls.Add(Me.Label1) + Me.Controls.Add(Me.label1) Me.Name = "Form1" Me.Text = "Names" Me.ResumeLayout(False) @@ -78,8 +78,8 @@ Partial Class Form1 End Sub - Friend WithEvents Label1 As Windows.Forms.Label - Friend WithEvents lstNames As Windows.Forms.ListBox - Friend WithEvents txtName As Windows.Forms.TextBox - Friend WithEvents btnAdd As Windows.Forms.Button + Private WithEvents btnAdd As Button + Private WithEvents txtName As TextBox + Private WithEvents lstNames As ListBox + Private WithEvents label1 As Label End Class diff --git a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/Main.resx b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/Form1.resx similarity index 100% rename from dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/Main.resx rename to dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/Form1.resx diff --git a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/Main.vb b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/Form1.vb similarity index 52% rename from dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/Main.vb rename to dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/Form1.vb index bef5f98437..3b06ba570f 100644 --- a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/Main.vb +++ b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/Form1.vb @@ -1,19 +1,9 @@ -Imports System.Windows.Forms -Imports System.Drawing - -Partial Public Class Form1 - - Public Sub New() - InitializeComponent() - End Sub - - Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load - - End Sub - +Public Class Form1 + ' Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click If Not String.IsNullOrWhiteSpace(txtName.Text) And Not lstNames.Items.Contains(txtName.Text) Then lstNames.Items.Add(txtName.Text) End If End Sub + ' End Class diff --git a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/My Project/Application.Designer.vb b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/My Project/Application.Designer.vb new file mode 100644 index 0000000000..007b31fc7d --- /dev/null +++ b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/My Project/Application.Designer.vb @@ -0,0 +1,37 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + +Namespace My + + 'NOTE: This file is auto-generated; do not modify it directly. To make changes, + ' or if you encounter build errors in this file, go to the Project Designer + ' (go to Project Properties or double-click the My Project node in + ' Solution Explorer), and make changes on the Application tab. + ' + Partial Friend Class MyApplication + + + Public Sub New() + MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows) + Me.IsSingleInstance = False + Me.EnableVisualStyles = True + Me.SaveMySettingsOnExit = True + Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses + End Sub + + + Protected Overrides Sub OnCreateMainForm() + Me.MainForm = Form1 + End Sub + End Class +End Namespace diff --git a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/My Project/Application.myapp b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/My Project/Application.myapp new file mode 100644 index 0000000000..0f12f32388 --- /dev/null +++ b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/My Project/Application.myapp @@ -0,0 +1,10 @@ + + + true + Form1 + false + 0 + true + 0 + true + \ No newline at end of file diff --git a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/NamesVB.vbproj b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/NamesVB.vbproj new file mode 100644 index 0000000000..13928b7a2d --- /dev/null +++ b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/NamesVB.vbproj @@ -0,0 +1,32 @@ + + + + WinExe + net6.0-windows + Sub Main + true + WindowsForms + + + + + + + + + + + True + True + Application.myapp + + + + + + MyApplicationCodeGenerator + Application.Designer.vb + + + + \ No newline at end of file diff --git a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/Program.vb b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/Program.vb deleted file mode 100644 index 3551285240..0000000000 --- a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/Program.vb +++ /dev/null @@ -1,15 +0,0 @@ -Imports System -Imports System.Collections.Generic -Imports System.Linq -Imports System.Threading.Tasks -Imports System.Windows.Forms - -Module Program - Sub Main(args As String()) - Application.SetHighDpiMode(HighDpiMode.SystemAware) - Application.EnableVisualStyles() - Application.SetCompatibleTextRenderingDefault(False) - Application.Run(New Form1()) - End Sub - -End Module diff --git a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/projectvb.vbproj b/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/projectvb.vbproj deleted file mode 100644 index 38f543443c..0000000000 --- a/dotnet-desktop-guide/net/winforms/get-started/snippets/create-app-visual-studio/vb/projectvb.vbproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - WinExe - net5.0-windows - true - Sub Main - - - - - - - \ No newline at end of file diff --git a/dotnet-desktop-guide/net/winforms/index.yml b/dotnet-desktop-guide/net/winforms/index.yml index d203b001d9..40335928e6 100644 --- a/dotnet-desktop-guide/net/winforms/index.yml +++ b/dotnet-desktop-guide/net/winforms/index.yml @@ -7,7 +7,7 @@ metadata: title: Windows Forms for .NET 6 documentation description: Learn about using Windows Forms, an open-source, graphical user interface for Windows, on .NET 6. ms.topic: landing-page - ms.date: 10/26/2020 + ms.date: 11/15/2021 # linkListType: architecture | concept | deploy | download | get-started | how-to-guide | learn | overview | quickstart | reference | sample | tutorial | video | whats-new diff --git a/dotnet-desktop-guide/net/winforms/overview/index.md b/dotnet-desktop-guide/net/winforms/overview/index.md index a52bd2a676..ce18ab01cb 100644 --- a/dotnet-desktop-guide/net/winforms/overview/index.md +++ b/dotnet-desktop-guide/net/winforms/overview/index.md @@ -1,7 +1,7 @@ --- title: What is Windows Forms description: This article gives an overview of Windows Forms with .NET Core and .NET 5. -ms.date: 10/26/2020 +ms.date: 11/15/2021 ms.topic: overview #Customer intent: As a developer, I want to understand the components of Windows Forms so that I can understand the overall picture of Windows Forms. --- @@ -16,13 +16,15 @@ There are two implementations of Windows Forms: 01. The open-source implementation hosted on [GitHub](https://github.com/dotnet/winforms). - This version runs on .NET 5 and .NET Core 3.1. The Windows Forms Visual Designer requires, at a minimum, [Visual Studio 2019 version 16.8 Preview](https://visualstudio.microsoft.com/downloads/?utm_medium=microsoft&utm_source=docs.microsoft.com&utm_campaign=inline+link&utm_content=download+vs2019+desktopguide+winforms). + This version runs on .NET 5+ (and .NET Core 3.1). The Windows Forms Visual Designer requires, at a minimum, [Visual Studio 2019 version 16.8](https://visualstudio.microsoft.com/downloads/?utm_medium=microsoft&utm_source=docs.microsoft.com&utm_campaign=inline+link&utm_content=download+vs2019+desktopguide+winforms). -01. The .NET Framework 4 implementation that's supported by Visual Studio 2019 and Visual Studio 2017. + The latest version of Windows Forms is for .NET 6 using [Visual Studio 2022 version 17.0](https://visualstudio.microsoft.com/downloads/?utm_medium=microsoft&utm_source=docs.microsoft.com&utm_campaign=inline+link&utm_content=download+vs2022+desktopguide+winforms). + +01. The .NET Framework 4 implementation that's supported by Visual Studio 2022, Visual Studio 2019, and Visual Studio 2017. .NET Framework 4 is a Windows-only version of .NET and is considered a Windows Operating System component. This version of Windows Forms is distributed with .NET Framework. -This Desktop Guide is written for Windows Forms on .NET 5. For more information about the .NET Framework version of Windows Forms, see [Windows Forms for .NET Framework](../../../framework/winforms/index.yml?view=netframeworkdesktop-4.8&preserve-view=true). +This Desktop Guide is written for Windows Forms on .NET 5 and later versions. For more information about the .NET Framework version of Windows Forms, see [Windows Forms for .NET Framework](../../../framework/winforms/index.yml?view=netframeworkdesktop-4.8&preserve-view=true). ## Introduction @@ -30,11 +32,11 @@ Windows Forms is a UI framework for building Windows desktop apps. It provides o With Windows Forms, you develop graphically rich apps that are easy to deploy, update, and work while offline or while connected to the internet. Windows Forms apps can access the local hardware and file system of the computer where the app is running. -To learn how to create a Windows Forms app, see [Tutorial: Create a new WinForms app (Windows Forms .NET)](../get-started/create-app-visual-studio.md). +To learn how to create a Windows Forms app, see [Tutorial: Create a new WinForms app](../get-started/create-app-visual-studio.md). ## Why migrate from .NET Framework -Windows Forms for .NET 5.0 provides new features and enhancements over .NET Framework. For more information, see [What's new in Windows Forms for .NET 5](../whats-new/index.md). To learn how to migrate an app, see [How to migrate a Windows Forms desktop app to .NET 5](../migration/index.md). +Windows Forms for .NET 6.0 provides new features and enhancements over .NET Framework. For more information, see [What's new in Windows Forms for .NET 6](../whats-new/net60.md) and [.NET 5](../whats-new/net50.md). To learn how to migrate an app, see [How to migrate a Windows Forms desktop app to .NET 5](../migration/index.md). ## Build rich, interactive user interfaces @@ -127,6 +129,6 @@ For step-by-step information about how to use these features, see the following ## See also -- [Tutorial: Create a new WinForms app (Windows Forms .NET)](../get-started/create-app-visual-studio.md) -- [How to add a form to a project (Windows Forms .NET)](../forms/how-to-add.md) -- [Add a control (Windows Forms .NET)](../controls/how-to-add-to-a-form.md) +- [Tutorial: Create a new WinForms app](../get-started/create-app-visual-studio.md) +- [How to add a form to a project](../forms/how-to-add.md) +- [Add a control](../controls/how-to-add-to-a-form.md)