消息框不显示任何C Sharp文本
本文关键字:Sharp 文本 任何 显示 消息 | 更新日期: 2023-09-27 17:52:36
我的消息框应该弹出并询问用户是否要下载新版本的应用程序,如果他们说不,它退出并告诉他们需要下载一个新的副本才能继续。如果他们说是,它会打开一个浏览器到前面提到的网址。现在,弹出消息框却什么也没出现。然而,每当我把代码给我的朋友,他尝试它,它工作。这是怎么了?使用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();
}
}
}
}
试试这个:
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;
}
}
}
}