在.NET控制台应用程序显示消息框

编程入门 行业动态 更新时间:2024-10-27 20:31:18
本文介绍了在.NET控制台应用程序显示消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何在 c#或vb 控制台应用程式中显示讯息方块? 类似的东西:

Console.WriteLine(Hello World); MessageBox.Show(Hello World);

Console.WriteLine(Hello) MsgBox(Hello)

在c#和vb中。 是否可能?

解决方案

控制台应用程序。但是请先在vb或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 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 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 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 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控制台应用程序显示消息框

本文发布于:2023-11-10 06:46:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574647.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制台   应用程序   消息   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!