简体   繁体   English

通过 C# 控制台应用程序发送 MessageBox

[英]Send MessageBox Via C# console application

I've researched about this and I see people saying to open References then add Systen.Windows.Forms but for me it shows Dependencies and when I add System_Windows_Forms in it, it says there is a error with "Forms" Sample Code我已经对此进行了研究,我看到人们说要打开 References 然后添加 Systen.Windows.Forms 但对我来说它显示了 Dependencies,当我在其中添加 System_Windows_Forms 时,它说“Forms”示例代码有错误

using System.Windows.Form
namespace Session_Client 
{
    class Program
    {
        MessageBox.Show("Stackoverflow");
    }
}

It for some reason shows the options of Input and Markup both not including MessageBox.Show由于某种原因,它显示了 Input 和 Markup 的选项都不包括 MessageBox.Show

Is there a possible solution?有可能的解决方案吗?

Your question is a little unclear, but here are two ways to show a message box in ac# console application.您的问题有点不清楚,但这里有两种方法可以在 ac# 控制台应用程序中显示消息框。

Method 1:方法一:

First you need to include this reference.首先,您需要包含此引用。

System.Windows.Forms;

To add the reference:添加引用:

You need to right click (in solution explorer) on your project name-> then add reference-> then .Net-> then select System.Windows.Forms.您需要右键单击(在解决方案资源管理器中)您的项目名称-> 然后添加引用-> 然后 .Net-> 然后选择 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.要在 c# 程序中添加引用,请右键单击解决方案资源管理器中显示的项目文件夹,添加引用 -> .Net -> 选择 System.Windows.Forms。

then you can use a MessageBox in your application.然后您可以在您的应用程序中使用 MessageBox。

MessageBox.Show("Stackoverflow");

Method 2:方法二:

Alternatively you can create a simple MessageBox yourself using some code...或者,您可以使用一些代码自己创建一个简单的 MessageBox ...

To do this you first need to create a property with the attribute of为此,您首先需要创建一个具有以下属性的属性

using System.Runtime.InteropServices;
[DllImport("User32.dll", CharSet = CharSet.Unicode)]
public static extern int MessageBox(IntPtr h, string m, string c, int type);

Then you can use this to call a MessageBox:然后您可以使用它来调用 MessageBox:

MessageBox((IntPtr)0, "Content", "Title", 0);

Answer formed from answers by Syed Osama Maruf and Nikhil Nambiar on this question related to the same problem.Syed Osama MarufNikhil Nambiar对与同一问题相关的这个问题的回答形成的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM