当前位置: 移动技术网 > IT编程>开发语言>.net > visual studio 2019使用net core3.0创建winform无法使用窗体设计器

visual studio 2019使用net core3.0创建winform无法使用窗体设计器

2020年06月23日  | 移动技术网IT编程  | 我要评论

制图cad,冒牌设计师,麦特屋

微软发布正式版net core3.0后,迫不及待的想体验一下用visual studio 2019在net core3.0下创建winform程序。创建方法很简单,和以前visual studio版本步骤差不多。

创建完成之后,尴尬的事情发生了,无法使用窗体设计器,双击form1.cs文件不行,使用快捷键shift+f7也不行,在网上找了很久,发现好多人都遇到过这种问题,目前有两种解决方案

方案1 项目中创建多目标框架,包含net framework和net core。

打开csproj文件,将目标框架更改为net452和netcoreapp3.0。最终修改结果如下:

<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>

注意,必须将targetframework更改为复数targetframeworks

更改完之后,系统会提示application未包含“sethighdpimode”的定义”和“当前上下文中不存在名称“highdpimode”
这是由于net core3.0加载窗体程序时多了下面一行代码:

application.sethighdpimode(highdpimode.systemaware);

我们只需要用#if过滤一下即可:

   /// <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());
    }
  }

方案2 添加winformsdesigner插件

创建winform core程序,点击扩展–>管理扩展,打开扩展管理窗体,选中联机,搜索winform designer。选择安装即可。

或者手动下载:

参考地址:https://github.com/dotnet/winforms/tree/master/documentation/designer-releases

添加完之后,期待已久的窗体设计器就可以出来了。

我目前使用的visual studio 2019的版本信息

到此这篇关于visual studio 2019使用net core3.0创建winform无法使用窗体设计器的文章就介绍到这了,更多相关vs2019创建winform内容请搜索移动技术网以前的文章或继续浏览下面的相关文章希望大家以后多多支持移动技术网!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网