Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I m having 12 forms in my application. I want to display a message box asking the user to close the existing opened child form before opening other.

I had tried the following the code:

C#
Form curfrm;

String a = " Please Close other open window ";

private void admissionForm1ToolStripMenuItem_Click(object sender, EventArgs e)
       {
           adfrm1 af1 = new adfrm1(null);
           if (curfrm != null)
           {
               MessageBox.Show(a);
               return;
           }
           else
           {
               curfrm = af1;
               af1.MdiParent = this;
               af1.Show();
           }


This doesn't allow me to open the other forms after closing the child form.

Thanks.
Posted
Updated 1-Mar-12 18:39pm
v3
Comments
Sergey Alexandrovich Kryukov 1-Mar-12 22:38pm    
What an abuse of simple human logic. I can imagine what a user of such thing can feel.
--SA
CodeHawkz 1-Mar-12 23:56pm    
@SA: He might be having his own reasons. Let's not critisize but try and help. :)
@Member 8658209: All you want to show is one child window at a time. Is it?

1 solution

If you wish to show only one child form at a time then use a simple token logic to implement the rule.

Have a global static variable, preferably a string that can store the current child form name, that would act as the token.

On all the child forms' constructor implement the following pesudo code -
VB
if GlobalToken = "" then
    GlobalToken = CurrentForm.Name
else
    Show Message
end if


On all the child forms' destructor clear the token -
VB
GlobalToken = ""
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900