if (MessageBox.Show ("Do you want to exit?", "Information", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
Application.Exit();
}
I wrote the code like above. Naturally, when No is called, I thought there would be no event such as hiding the program (call the Hide function) or ending, but it was hidden as if there was a Hide() function.(Remain in process) Is there a way to prevent this?
c# modal visual-studio
Prevention is...What does it mean?Event processing when the user clicks the x at the top of the window or clicks the end button of the program.If the DialogResult result is No, skip the exit logic.
You can do the Form Closing process as shown below.
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
varresult = MessageBox.Show ("Are you sure you want to exit the program?"", "Check Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (DialogResult.No == result) e.Cancel = true;
}
© 2024 OneMinuteCode. All rights reserved.