MessageBox在C Sharp中没有显示任何文本

时间:2011-04-22 03:21:00

标签: c#

我的消息框应该弹出并询问用户是否要下载新版本的应用程序,如果他们拒绝,则会退出并告诉他们需要下载新副本才能继续。如果他们说是的,它会打开上述网址的浏览器。此时,弹出消息框,不显示任何内容。但是,每当我将代码交给我的朋友并且他尝试了它时,它就会起作用。这有什么不对?我使用Microsoft Framework 4.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)
    {
        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();
}
}

    }
}

1 个答案:

答案 0 :(得分: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;
}
}

    }
}