![]() The control might initially be named something else, such as webView21. In the Properties panel, in the Design section, set the (Name) property to webView (lowercase 'w', capital 'V', no numeric suffix). Make sure the new WebView2 control on the form is selected. In the Toolbox, click or drag the WebView2 control onto the Forms Designer canvas of the control you added, such as Form2.cs:ĭrag the sides of the WebView2 control to make it fill almost all of the canvas. 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. The Visual Studio window opens, showing the baseline WinForms project in the Solution Explorer, and showing a Form Designer window:Īn empty Form1 window opens, from the fresh WinForms project: 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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |