2011-04-22 45 views
1

我的消息框應該彈出並詢問用戶是否要下載新版本的應用程序,如果他們說不,則退出並告訴他們需要下載新的副本繼續。如果他們說是的話,它會打開一個瀏覽器到上述的網址。現在,消息框彈出,沒有任何顯示。然而,每當我將代碼交給我的朋友並且他嘗試了它,它就會奏效。這裏有什麼問題?我使用Microsoft Framework 4.0進行編譯。MessageBox在C中沒有顯示任何文本

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 

namespace ProjectTest 
{ 
    public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 
     Form1_FormClosing(); 
    } 

    private void Form1_FormClosing() 
    { 
    const string message = 
    "There's an updated version of this program available. Would you like to download now?"; 
const string caption = "Please update"; 
var result = MessageBox.Show(message, caption, 
          MessageBoxButtons.YesNo, 
          MessageBoxIcon.Question); 

// If the no button was pressed ... 
if (result == DialogResult.No) 
{ 
    MessageBox.Show("Program will close now. If you want to use this program please update to the newest version.", "Please update"); 
    this.Close(); 
} 
else if (result == DialogResult.Yes) 
{ 
    System.Diagnostics.Process.Start("http://www.google.com"); 
    this.Close(); 
} 
} 

    } 
} 
+0

你的代碼看起來像它應該工作。你給它的朋友,他是否和你一樣運行相同的操作系統?小部件的大小和樣式從版本變爲版本,這導致事物顯示不同。 – 2011-04-22 03:27:08

+0

事情是,我在Visual Studio 2008和2010上運行並編譯了Windows 7,但沒有奏效。然後我在XP上運行VS 2010,但它仍然無法運行。嘗試4.0和3.5,它仍然沒有工作。現在一言不發。 – JacksonDaHaxz 2011-04-22 03:29:21

+0

我做了這個改變,messagebox仍然顯示空白。 – JacksonDaHaxz 2011-04-22 03:32:45

回答

0

試試這個:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 

namespace ProjectTest 
{ 
    public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 
     this.Close(); 
    } 

    private void Form1_FormClosing() 
    { 
    const string message = 
    "There's an updated version of this program available. Would you like to download now?"; 
const string caption = "Please update"; 
var result = MessageBox.Show(message, caption, 
          MessageBoxButtons.YesNo, 
          MessageBoxIcon.Question); 

// If the no button was pressed ... 
if (result == DialogResult.No) 
{ 
    MessageBox.Show("Program will close now. If you want to use this program please update to the newest version.", "Please update"); 
       e.Cancel = false; 
} 
else if (result == DialogResult.Yes) 
{ 
    System.Diagnostics.Process.Start("http://www.google.com"); 
       e.Cancel = false; 
} 
} 

    } 
} 
+0

錯誤預期的類,委託,枚舉,接口或結構 – JacksonDaHaxz 2011-04-22 03:40:07

+0

OK〜我發佈整個代碼,我想你可能會錯過一些「}」或其他符號或錯誤的命名空間來獲取這些錯誤信息。 **錯誤預期的類,委託,枚舉,接口或結構** – Maidot 2011-04-22 03:46:12