すべてのテキストボックスと変数を簡単にリセットできるように、メインフォームをリセットしようとしています。Progam.csにブール値を追加して、フォームを閉じてから再度開いている間、アプリケーションを開いたままにしておくことができるようにしました。閉じようとすると、on_closeingが2回も発生します。それを止めるために何をすべきかはわかりませんが、それは単純なものでなければならないことは知っています。
Program.cs:
static class Program
{
public static bool KeepRunning { get; set; }
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
KeepRunning = true;
while (KeepRunning)
{
KeepRunning = false;
Application.Run(new Form1());
}
}
}
フォーム1:
private void button1_Click(object sender, EventArgs e)
{
Program.KeepRunning = true;
this.Close();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult dialogResult = MessageBox.Show("You have unsaved work! Save before closing?", "Save?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
if (dialogResult == DialogResult.Yes)
{
e.Cancel = true;
MessageBox.Show("saving then closing");
Application.Exit();
}
if (dialogResult == DialogResult.No)
{
MessageBox.Show("closing");
Application.Exit();
}
if (dialogResult == DialogResult.Cancel)
{
e.Cancel = true;
MessageBox.Show("canceling");
}
}