Form Closing help
- by Michael Quiles
How can I call the button1_Click event in the form closing event so I don't have to copy and paste the code from 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
}