|
-
Dec 19th, 2006, 06:55 AM
#1
Thread Starter
Lively Member
Closing MDI Parent form
Hai
i am working with MDI forms. i am having parent form (mainfrm). and child forms(chld1,chl2)
from mainfrm i opened chld1 using
chld1.show();
now if i close parent form (mainfrm) the child windows r getting closed. i should restrict user to close parent form when child form is opened.
for that i am trying to use
chld.ShowDialog();
But unable to do that
Please help me in this regard
Thanks and Regards
VInay Kumar
-
Dec 19th, 2006, 06:12 PM
#2
Re: Closing MDI Parent form
An MDI child form cannot be a modal dialogue. To prevent the parent form closing you can handle the FormClosing event:
Code:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// Cancel the closing action if and only if there are child forms.
e.Cancel = (this.MdiChildren > 0);
}
Note that this assumes that you're using VB2005. In previous versions you'd handle the Closing event instead. Please make sure you specify your version in future.
Also, this will prevent Windows shutting down if your app has child forms open. You'd have to make a special case for if the system was shutting down. I don't know exactly how to do that because I've never had to myself but I know that the appropriate code has been posted before.
-
Dec 20th, 2006, 01:39 AM
#3
Thread Starter
Lively Member
Re: Closing MDI Parent form
Thats a great reply. Thank u so much
Just one more doubt added to it.
i am having parent form(mainfrm)
i am having 2 child forms(frm1,frm2)
i will go to frm1 and frm2 through mainfrm
if frm1 or frm2 is open, i should not able to select mainfrm
like frm1.ShowDialog();
but if i am using this in MDI i am getting error
Can i get answer for this one too.
Thank u so much in Advance
Regards
Vinay Kumar
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
|