[問題] MessageBox.Show()的問題

看板C_Sharp作者 (ppp)時間15年前 (2010/11/20 16:54), 編輯推噓2(206)
留言8則, 4人參與, 最新討論串1/1
以下是我的程式碼 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) { int x = 10, y=0,re; try { re=x/y; } catch (System.DivideByZeroException ex) { MessageBox.Show("除數不可以為0"); } finally { MessageBox.Show("finally"); } Console.Read(); } } } 我要使用MessageBox.Show的方法,先查了msdn知道要 using System.Windows.Forms; 在編譯後,它卻告訴我 命名空間 'System' 中沒有型別或命名空間名稱 'Windows' (您是否遺漏了組件參考?) 我找不出原因 請各位為什麼會有錯呢 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.117.3.231

11/20 16:57, , 1F
console application沒有form吧?
11/20 16:57, 1F

11/20 16:58, , 2F
console application應該不能用windows的組件
11/20 16:58, 2F

11/20 17:06, , 3F
其實是可以的,方法在這裡:http://ppt.cc/0_7(
11/20 17:06, 3F
※ 編輯: hiroshima 來自: 59.117.3.231 (11/20 17:11)

11/20 17:12, , 4F
感謝james
11/20 17:12, 4F

11/20 17:50, , 5F
所以程式是Copy來的?因為沒加入參考前用using是打不出來的
11/20 17:50, 5F

11/20 17:53, , 6F
應該瞭解一下"加入參考"是什麼意思和加入的是什麼東西...
11/20 17:53, 6F

11/20 18:24, , 7F
喔喔,也是可以這樣啦,我通常用console就不用form了..XD
11/20 18:24, 7F

11/20 18:31, , 8F
一般來說我也覺得別混用比較好,但技術上是可以做到的
11/20 18:31, 8F
其實,我是照書上所講的來寫的,書上沒有完整的程式,我以為以用主控台應用程式來寫 原來是要用windows form應用程式來寫,書上也沒講"加入參考"的東西,不曉得是沒有講, 還是我沒讀到,謝謝各位囉 ※ 編輯: hiroshima 來自: 59.117.10.164 (11/20 19:39)
文章代碼(AID): #1CvuojaG (C_Sharp)