控制台应用问题

pko*_*iej 1 .net c# console-application

我正在徘徊为什么当我创建控制台应用程序并"转换"主要方法与创建Windows窗体项目时自动生成的main方法相同时,控制台仍然出现在屏幕上:

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());
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

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

善良的Regadrs PK

Meh*_*ari 5

您应该将项目属性中的目标类型设置为"Windows应用程序".这相当于/target:winexe编译器开关.它将改变subsystem二进制文件头,告诉Windows不要打开一个shell窗口.