[C#]主控台應用程式顯示 MessageBox

  • 19379
  • 0
  • 2010-08-03

[C#]主控台應用程式顯示 MessageBox

 

1. 問題描述

如何在 主控台應用程式 顯示 MessageBox

 

2. 方法

MessageBox 訊息方塊,組件是來自 System.Windows.Forms (在 System.Windows.Forms.dll 中)

所以想要在 主控台應用程式 顯示 MessageBox,只要加入 System.Windows.Forms.dll 就可以了

 

2.1 新增 主控台應用程式

image

 

2.2 將 System.Windows.Forms.dll 加入參考

在方案總管中,方案下的參考,滑鼠右鍵,點選加入參考(R)

image

 

選擇 System.Windows.Forms,按下 確定

image

 

將 using System.Windows.Forms;


using System.Windows.Forms;

 

2.3 使用 MessageBox


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            MessageBox.Show("Show Message");
        }
    }
}

 

3. 執行結果

image

 

4. 參考

MessageBox in a Console Window