Solved

Disable Close Option on MDI Parent, Enable on Child

Posted on 2002-03-15
13
286 Views
Last Modified: 2010-05-02
I'm trying to make a menu editor that functions similar to the way that MS Office apps do.  I have a File/Close menu option in the MDI application, but I can't figure out how to code it.  

If the user clicks close (or uses the shortcut) I want to close the MDI child that has focus.  And, I want the close option to be disabled if the MDI parent is the only thing open.

Right now, the close option is enabled on all forms (both parent and child).  Also, if I put an Unload Me in the Click event of mnuClose, the MDI parent unloads, thereby unloading the application - rather than unloading the child form that has focus.
0
Comment
Question by:cnealy
  • 8
  • 5
13 Comments
 

Expert Comment

by:bill02
ID: 6869462
all you need is this code


Unload ActiveForm

or if its on a button thats not on the mdi form then

unload MDIForm.Activeform

that should do it
0
 
LVL 1

Author Comment

by:cnealy
ID: 6869472
Great!  Unload ActiveForm Worked.

Now ... how do I disable the Close menu option if the MDI parent is the only form that's loaded?
0
 
LVL 1

Author Comment

by:cnealy
ID: 6869477
Great!  Unload ActiveForm Worked.

Now ... how do I disable the Close menu option if the MDI parent is the only form that's loaded?
0
 

Expert Comment

by:bill02
ID: 6869493
If ActiveForm Is Nothing Then
disable button
End If
that should be all you need to do
0
 
LVL 1

Author Comment

by:cnealy
ID: 6869503
Where do I put the code?
0
 
LVL 1

Author Comment

by:cnealy
ID: 6878208
Bill - when you explain where to put the code, I can accept your answer.  
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Expert Comment

by:bill02
ID: 6878671
when do you want the button to be unabled you could put them on child form close you could put them on form load form initialize when do you want it to become enabled put the code there
0
 
LVL 1

Author Comment

by:cnealy
ID: 6878783
I want the close button to be enabled only when the MDI parent is the only form that is loaded.  So, I'm still unclear on where to put it.   I tried putting it in the MDI Parent's Activate event, but that event only fires once when the application is initially loaded.

Any details (code examples)  you can provide would be great.

Thanks.
0
 

Accepted Solution

by:
bill02 earned 50 total points
ID: 6878846
on child form unload
button.enabled = false
on child forms gotfocus
button.enabled = true
on mdiform load
If ActiveForm Is Nothing Then
button.enabled = false
End If
this is the easiest way there is another that im not to sure of thats the link mode on mdi and child forms you could set the links and when a link closes check to see if activeform but im not sure how that works
0
 
LVL 1

Author Comment

by:cnealy
ID: 6878883
Does this mean that I'll need to code Unload and GotFocus events on every child form one by one?  I have about 25 forms, so this will take awhile.  Can you think of any other way that I can determine if the MDI parent form is the only form that's open?  Unfortunately, I don't see a GotFocus event for the MDI parent ....
0
 
LVL 1

Author Comment

by:cnealy
ID: 6878886
Does this mean that I'll need to code Unload and GotFocus events on every child form one by one?  I have about 25 forms, so this will take awhile.  Can you think of any other way that I can determine if the MDI parent form is the only form that's open?  Unfortunately, I don't see a GotFocus event for the MDI parent ....
0
 

Expert Comment

by:bill02
ID: 6878895
yes i know that is the problem i was running into to see if the mdi form has focus im not sure how to obtain that the only way i know how to do it is put it on every form
0
 
LVL 1

Author Comment

by:cnealy
ID: 6878918
Thanks, Bill02.  
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now