MessageBox not showing any text in C Sharp
my message box is supposed pop up and ask the user if they want to download a new version of the application and if they say no, it exits and tells them that they need to download a new copy to continue. If they say yeah, it opens a browser to the aforementioned web address. Right now, the message box pops up and nothing appears. However, whenever I gave the code to my friend and he tried it, it worked. What's wrong here? I compiled with 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)
{
Syste开发者_Go百科m.Diagnostics.Process.Start("http://www.google.com");
this.Close();
}
}
}
}
Try this:
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;
}
}
}
}
精彩评论