Visual studio 2019 uses net core 3.0 to create WinForm, unable to use form designer

Time:2020-9-15

After Microsoft released the official version of net core 3.0, I can’t wait to experience creating WinForm program under net core 3.0 with visual studio 2019. The creation method is very simple, similar to the previous version of visual studio.

After the creation is completed, embarrassing things happen. You can’t use the form designer. Double clickForm1.csNo file. Use the shortcut keyshift+F7No, I have been looking for it on the Internet for a long time and found that many people have encountered this problem. There are two solutions at present

In scheme 1, a multi-objective framework is created, including net framework and net core.

Open the csproj file and change the target framework to net452 and netcoreapp 3.0. The final modification results are as follows:


<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
 <PropertyGroup>
  <OutputType>WinExe</OutputType>
  <TargetFrameworks>net452;netcoreapp3.0</TargetFrameworks>
  <UseWindowsForms>true</UseWindowsForms>
  <ApplicationIcon />
  <StartupObject />
  <AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
 </PropertyGroup>
</Project>

Note that theTargetFrameworkChange to pluralTargetFrameworks

After the change, the system will prompt that the application does not contain the definition of “sethighdpimode” and “the name” highdpimode “does not exist in the current context
This is because when net core 3.0 loads the form program, the following line of code is added:


Application.SetHighDpiMode(HighDpiMode.SystemAware);

We just need to use it#IfFilter it


   /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
#if netcoreapp3_0
      Application.SetHighDpiMode(HighDpiMode.SystemAware);
#endif
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      Application.Run(new Form1());
    }
  }

Scenario 2 add WinForms designer plug-in

Create the WinForm core program, click extension – > Manage extension to open the extension management form, select online and search for WinForm designer. Select Install.

Or download it manually: WinForms Designer

Reference address: https://github.com/dotnet/winforms/tree/master/Documentation/designer-releases

After adding, the long-awaited form designer will be available.

Version information of visual studio 2019 I currently use

This article about visual studio 2019 using net core 3.0 to create WinForm, can not use the form designer to introduce here, more related vs2019 to create WinForm content, please search the previous articles of developeppaer or continue to browse the related articles below, I hope you can support developeppaer more in the future!