研究了一下,解决了问题.方法如下:
program.cs:
static class Program
{
private static Form1 f;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
f = new Form1();
f.Show();
Application.Run();
}
}
Form1.cs:
protected override void Dispose(bool disposing)
{
DialogResult d = MessageBox.Show("Are you sure to exit?", "Attention", MessageBoxButtons.OKCancel);
string s = d.ToString();
if (s == "OK")
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
Application.Exit();
}
}