[英]Send MessageBox Via C# console application
我已经对此进行了研究,我看到人们说要打开 References 然后添加 Systen.Windows.Forms 但对我来说它显示了 Dependencies,当我在其中添加 System_Windows_Forms 时,它说“Forms”示例代码有错误
using System.Windows.Form
namespace Session_Client
{
class Program
{
MessageBox.Show("Stackoverflow");
}
}
由于某种原因,它显示了 Input 和 Markup 的选项都不包括 MessageBox.Show
有可能的解决方案吗?
您的问题有点不清楚,但这里有两种方法可以在 ac# 控制台应用程序中显示消息框。
方法一:
首先,您需要包含此引用。
System.Windows.Forms;
添加引用:
您需要右键单击(在解决方案资源管理器中)您的项目名称-> 然后添加引用-> 然后 .Net-> 然后选择 System.Windows.Forms。 要在 c# 程序中添加引用,请右键单击解决方案资源管理器中显示的项目文件夹,添加引用 -> .Net -> 选择 System.Windows.Forms。
然后您可以在您的应用程序中使用 MessageBox。
MessageBox.Show("Stackoverflow");
方法二:
或者,您可以使用一些代码自己创建一个简单的 MessageBox ...
为此,您首先需要创建一个具有以下属性的属性
using System.Runtime.InteropServices;
[DllImport("User32.dll", CharSet = CharSet.Unicode)]
public static extern int MessageBox(IntPtr h, string m, string c, int type);
然后您可以使用它来调用 MessageBox:
MessageBox((IntPtr)0, "Content", "Title", 0);
由Syed Osama Maruf和Nikhil Nambiar对与同一问题相关的这个问题的回答形成的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.