gpt4 book ai didi

c# - 控制台应用问题

转载 作者:太空宇宙 更新时间:2023-11-03 20:46:16 25 4
gpt4 key购买 nike

我想知道为什么当我创建控制台应用程序并将主要方法“转换”为与创建 Windows 窗体项目时自动生成的主要方法看起来相同时,控制台仍然出现在屏幕上:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Windows.Forms;

namespace Chapter16
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new CultureTest());
}
}
}

此代码与位于 Windows 窗体应用程序的 Program.cs 中的代码相同。问题是控制台仍然出现在屏幕上,而在 Windows 窗体项目中则不是这样。这是为什么?

好心人对战

最佳答案

您应该将项目属性中的目标类型设置为“Windows 应用程序”。这相当于 /target:winexe 编译器开关。它会改变二进制 header 中的 subsystem 以告诉 Windows 不要打开 shell 窗口。

关于c# - 控制台应用问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/788685/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com