如何在窗體關閉事件中調用button1_Click事件,因此我不必從button1_Click複製和粘貼代碼?窗體關閉幫助
public void button1_Click(object sender, EventArgs e)
{
//Yes or no message box to exit the application
DialogResult Response;
Response = MessageBox.Show("Are you sure you want to Exit?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
if (Response == DialogResult.Yes)
// Exits the application
Application.Exit();
}
public void xGameThemeComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
string folder = Application.StartupPath;
string theme = (string)xGameThemeComboBox.Items[xGameThemeComboBox.SelectedIndex];
string path = System.IO.Path.Combine(folder, theme + ".jpg");
Image newImage = new Bitmap(path);
if (this.BackgroundImage != null) this.BackgroundImage.Dispose();
{
this.BackgroundImage = newImage;
}
}
private void xGameForm_FormClosing(object sender, FormClosingEventArgs e)
{
// call button1_Click here
}
-1:將顯示對話框兩次(一次用於按鈕單擊,一次用於Application.Exit'提升FormClosing事件 – Powerlord 2010-06-01 15:05:50
@R Bemrose:Application.Exit不會增加FormClosing至i請記住 – Andrey 2010-06-01 15:09:20
是的,我甚至在自己的答案中引用了文檔,並鏈接到它。 – Powerlord 2010-06-01 15:35:54