在.NET控制台应用程序显示消息框 [英] Show message Box in .net console application
问题描述
如何在.net c#或vb 控制台应用程式中显示讯息方块?
类似的东西:
Console.WriteLine(Hello World);
MessageBox.Show(Hello World);
或
Console.WriteLine(Hello)
MsgBox(Hello)
在c#和vb中。
是否可能?
控制台应用程序。但是请先在vb.net或c#控制台应用程序中包含此引用
System.Windows.Forms;
那么你可以为c#控制台应用程序执行以下代码:
使用System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ConsoleApplication6
{
class Program
{
static void Main(string [] args)
{
MessageBox.Show(Hello World);
}
}
}
你可以在包含上述引用之后简单编写代码
模块Module1
Sub Main $ b MsgBox(Hello)
Console.ReadKey()
结束子
结束模块
参考:
net程序右键单击(在解决方案资源管理器中)您的项目名称 - >然后添加reference->然后.Net->然后选择System.Windows.Forms。
要在c#程序中添加引用,请右键单击在解决方案资源管理器中显示的项目文件夹添加引用 - > .Net - >选择System.Windows.Forms。
根据相关问题的此回答进行调整。
How to show a message box in a .net c# or vb console application ? Something like:
Console.WriteLine("Hello World"); MessageBox.Show("Hello World");
or
Console.WriteLine("Hello") MsgBox("Hello")
in c# and vb respectively.
Is it possible?解决方案We can show a message box in a console application. But first include this reference in your vb.net or c# console application
System.Windows.Forms;
then you can do the below code for c# console application:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; namespace ConsoleApplication6 { class Program { static void Main(string[] args) { MessageBox.Show("Hello World"); } } }
For the vb.net application you can simply code after inclusion of above mentioned reference
Module Module1 Sub Main() MsgBox("Hello") Console.ReadKey() End Sub End Module
Reference:
To add reference in vb.net program right click (in solution explorer) on your project name-> then add reference-> then .Net-> then select System.Windows.Forms.
To add reference in c# program right click in your project folders shown in solution explorer on add references-> .Net -> select System.Windows.Forms.Adapted from this answer to a related question.
这篇关于在.NET控制台应用程序显示消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!