|
-
May 8th, 2007, 07:11 PM
#1
Thread Starter
Lively Member
[RESOLVED] [2005] MDI and Childs problems
Hi,
My English is not native, sorry.
I have MDI form and Child form.
I added "Form_Closing" event to the MDI code file. the following is the code:
c# Code:
private void frmMainMdi_FormClosing(object sender, FormClosingEventArgs e)
{
// Hold the MessageBox button pressed
DialogResult diaResult;
// Show Message to the User
diaResult = MessageBox.Show("Are you sure you want to cancel the setup?",
"Exit Setup",
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button2);
// Checking which button as been pressed
if (diaResult == DialogResult.No)
{
// CANCEL pressed, set focus to the program
e.Cancel = true;
}
else
{
// YES pressed, exit the program
this.Dispose();
Application.Exit();
}
}
Now, in the child form i have CANCEL button that suppose to teminate the application if the user press YES.
I added to the click event the following code:
c# Code:
private void btnCancel_Click(object sender, EventArgs e)
{
Application.Exit();
}
And now I am having the problem,
I am getting an error when I try to cancel the program and the error points to the cancel button, application.exit();
the following is the VS2005 ERROR:
System.InvalidOperationException was unhandled
Message="Collection was modified; enumeration operation may not execute."
Source="mscorlib"
How can I terminate the program from runnning when pressing the cancel button?
Thanks
VBDC
Last edited by vbdc; May 8th, 2007 at 07:14 PM.
-
May 8th, 2007, 07:21 PM
#2
Re: [2005] MDI and Childs problems
You need to get rid of this for a start:
C# Code:
else
{
// YES pressed, exit the program
this.Dispose();
Application.Exit();
}
If the FormClosing event is raised it's because your form is closing. If it's closing that means that it is going to be disposed and the application will exit. You should not be disposing the form and exiting the application at that point.
What you're doing is like you checking if the door is closing and, if it is, closing the door. That's not logical. I don't know whether that will fix your issue or not but it sure won't hurt. Fix that and then try again. If the issue persists then post back.
Also, when asking for user confirmation of an action they requested you should be using OKCancel, which is the Windows convention, not YesNo.
-
May 8th, 2007, 07:37 PM
#3
Thread Starter
Lively Member
Re: [2005] MDI and Childs problems
jmcilhinney,
Thanks, I did what you said and It works great.
Thank you again.
VBDC
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|