且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 .Net Core 类库中使用 Windows 窗体 - .NET Core 控件库

更新时间:2023-12-06 09:13:40

更新:在 VS 2019 的更高版本中(我尝试了 16.8.2 版),有一个用于 .NET Core 的 Windows 窗体控件库 的项目模板.>

Update: In later versions of VS 2019 (I tried Version 16.8.2) there is a project template for Windows Forms Control Library for .NET Core.

目前Windows Forms .NET Core 处于预览模式,我不知道任何官方的 Nuget 包或 VS 2019 16.2.2 中 .NET Core 中 Windows 窗体控件库的项目模板.

Currently Windows Forms .NET Core is in Preview mode and I don't know any official Nuget package or Project template for Windows Forms Control Library in .NET Core in VS 2019 16.2.2.

但是要创建Windows 窗体控件库,您可以使用以下说明:

But to create a Windows Forms Control Library, you can use the following instructions:

  1. 添加类型为 Class Library (.NET Core)
  2. 的新项目
  3. 项目创建后,右键单击项目文件并选择Edit Project File
  4. 将项目 SDK 更改为
  5. 通过添加 true 将 Windows 窗体指定为 UI 技术.

现在项目文件应该如下所示:

Now the project file should be like the following:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <OutputType>Library</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>
</Project>

现在您可以向该项目添加诸如 FormUserControl 之类的 Windows 表单元素,并且可以毫无问题地构建项目.

Now you can add Windows forms elements like Form or UserControl to this project and build the project without any problem.