To enable WebView2 to be displayed in the Toolbox, select Tools > Options > General > and set the Automatically Populate Toolbox setting to True. In Visual Studio 2017, by default, WebView2 isn't displayed in the Toolbox. In the Toolbox, click WebView2 Windows Forms Control to expand the options. Here's where you add WebView2-specific content to the app: The project now has an additional form, with filename Form2.cs, shown in the Form Designer and in Solution Explorer:Ĭlick the Form1 canvas. On the right, select Form (Windows Forms), and then click the Add button: In the Add New Item window, on the left, select Visual C# Items > Windows Forms. Select Project > Add Form (Windows Forms). The starter project has a Form1.cs form already, but we'll add another, as Form2.cs, to see how to do that. Now that the WebView2 SDK is installed for the WinForms project, add a WebView2 control to the app, as follows: Step 5 - Create a single WebView2 control You've added the WebView2 SDK to the project, but haven't added any WebView2 code to the project yet. The running project displays the same empty window as before: Select Debug > Start Debugging ( F5) to build and run the project. Select File > Save All ( Ctrl+ Shift+ S) to save the project. To zoom, right-click > Open image in new tab.Ĭlick the Install (or Update) button. In the search bar, type WebView2, and then below the search bar, click 2 to select it: The NuGet Package Manager opens in Visual Studio. In Solution Explorer, right-click the project name (not the solution name above it), and then select Manage NuGet Packages: Use NuGet to add the WebView2 SDK to the project, as follows: You install the 2 SDK NuGet package for use by the current project. Step 4 - Install the WebView2 SDKįor every WebView2 project, you use the NuGet package manager within Visual Studio to add the WebView2 SDK to the project. Next, set up the project to add WebView2 content. You now have an empty WinForms project that runs. Select File > Save All ( Ctrl+ Shift+ S).Īn empty Form1 window opens, from the fresh WinForms project: The Visual Studio window opens, showing the baseline WinForms project in the Solution Explorer, and showing a Form Designer window: In the Location text box, enter a path, such as "C:\Users\username\Documents\MyWebView2Projects". This tutorial article uses the name WinForms_GettingStarted, like the repo's directory name for the completed project. In the Project name text box, enter a project name. Make sure the name matches, with a C# icon and then the name Windows Forms App (.NET Framework). Select the C# Windows Forms App (.NET Framework) card. Search results appear, listing project types. In the Search text box, paste or start typing the following: C# Windows Forms App (.NET Framework) The Visual Studio Create a new project window opens. On the right, click the Create a new project card. The Visual Studio Open recent window appears: Start with a basic desktop project that contains a single main window. If Visual Studio isn't installed already, open the page Microsoft Visual Studio in a new window or tab, and install Visual Studio 2017 or later, such as Visual Studio 2022 Professional. Microsoft Visual Studio Code is not supported for this tutorial. The sample in the repo might not be as up-to-date as a project that you create by using the latest Visual Studio project templates. Solution file: WebView2GettingStarted.sln.A completed version of this tutorial project is available in the WebView2Samples repo directory WinForms_GettingStarted. See Download the WebView2Samples repo in Set up your Dev environment for WebView2. This will give you the latest code and project structure.Ĭlone or download the WebView2Samples repo, open the completed project in Visual Studio, and follow the steps in this article to understand creating the WinForms project and understand the added WebView2 code. Step 1 - Optionally clone or download the WebView2Samples repoĬreate a new project in Visual Studio starting from a project template, using the steps in the sections below. Learn about WebView2 concepts along the way.Install the 2 SDK package for the WinForms project. Use the C# Windows Forms App (.NET Framework) Visual Studio project template to create a WinForms project.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |