C# 有没有办法用C将我的控制台应用程序转换成Windows窗体应用程序?

C# 有没有办法用C将我的控制台应用程序转换成Windows窗体应用程序?,c#,visual-studio,winforms,console-application,C#,Visual Studio,Winforms,Console Application,我创建了一个控制台应用程序,但我想将其转换为windows窗体应用程序 我发现它似乎是我所需要的,但当我试图使用System.Windows.Forms时,收到了一条错误消息 这是我收到的错误消息: 错误1命名空间“System”中不存在类型或命名空间名称“Windows”。是否缺少程序集引用 是否还有其他步骤,或者与VS 2008有所不同?您需要添加对System.Windows.Forms的引用。右键单击项目并选择“添加引用” 在.NET选项卡上选择前面提到的引用。您需要添加对WinForm

我创建了一个控制台应用程序,但我想将其转换为windows窗体应用程序

我发现它似乎是我所需要的,但当我试图使用System.Windows.Forms时,收到了一条错误消息

这是我收到的错误消息:

错误1命名空间“System”中不存在类型或命名空间名称“Windows”。是否缺少程序集引用


是否还有其他步骤,或者与VS 2008有所不同?

您需要添加对System.Windows.Forms的引用。右键单击项目并选择“添加引用”


在.NET选项卡上选择前面提到的引用。

您需要添加对WinForms程序集的引用

在解决方案上单击鼠标右键,然后选择“添加引用” 选择System.Windows.Forms并点击OK
您可能需要对System.Data执行相同的操作,具体取决于您的项目设置

请确保在项目的引用中添加System.Windows.Forms程序集。在解决方案资源管理器中,右键单击“引用”,然后在.NET选项卡下找到System.Windows.Forms程序集并添加它。

最简单的方法:

从.Net Core 3开始,最简单的方法是将Program.cs备份到磁盘上的某个位置,或者使用git并在Program.cs所在的位置运行以下命令:

dotnet new winforms --force
它将替换Program.cs和.csproj。然后,只需从旧的Program.cs复制所需的代码。就这样

对于手动转换项目,这可能会有所帮助:

以下是使用dotnet新winforms生成的.Net Core 3项目的外观:


谢谢这起作用了。对于系统数据,您的意思是添加对它的引用?
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>

</Project>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LinkInterceptor
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}