如何在后台显示没有控制台或表单的消息框?

How to show message box without console or form in background?

我是编程新手 (c#)。我在 VBScript 中看到我们可以显示消息框(独立)。我想在 C# 中做同样的事情,只是为了学习,但是执行时的代码在后台显示一个控制台或表单以及一个消息框。是否可以在程序执行时只显示消息框?

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

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            MessageBox.Show("My message");
        }
    }
}

对于控制台项目,您可以隐藏控制台如下:

  • 在解决方案资源管理器中右键单击项目
  • Select 属性
  • 转到项目属性中的 Application 选项卡。
  • 输出类型 组合框从 "Console Application" 更改为 "Windows Application"。