Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 10th, 2005, 2:02 PM   #1
cloud-
Hobbyist Programmer
 
Join Date: Jan 2005
Posts: 110
Rep Power: 4 cloud- is on a distinguished road
MDI forms - menu trouble

well,.. I have an mdi form with a few menus...one of these menus happenes to be what forms/windows are in view. When the child forms are unloaded they obviously need to be unchecked from the view, but when using:
private sub childform_unload()
frmmain.menuthiswindow.checked = false
end sub
I get the error message:
Only one MDI form allowed.
all i want to do is make the child form change the check status for a menu in the main form.

anyone know how i can do this?

thanks
cloud- is offline   Reply With Quote
Old Aug 11th, 2005, 1:03 PM   #2
BrianN
Newbie
 
Join Date: Aug 2005
Posts: 6
Rep Power: 0 BrianN is on a distinguished road
Are you saying that you want to make it so that it has a list of all the forms and then the checkmark is on the form that has to focus?

Or do you have a certain child forms that appear in the menu and you want the checks to appear on the forms that are visible?
BrianN is offline   Reply With Quote
Old Aug 11th, 2005, 1:43 PM   #3
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
It's possible that frmMain is not actually loaded when this event fires, and get/setting a property would cause VB to actually load and create a new instance of the (MDI) form, hence your error (as opposed to raising an error like in any other sane language!). Try debugging on step thru or setting a break point on that event to see when it is raised
Rory is offline   Reply With Quote
Old Aug 11th, 2005, 2:28 PM   #4
cloud-
Hobbyist Programmer
 
Join Date: Jan 2005
Posts: 110
Rep Power: 4 cloud- is on a distinguished road
hi the error only happens when i try to change the main forms menu check status with one of its child forms events (unload)

and heres pictures to explain what i mean


^--- when i click the checks the windows show/hide and boxes are checked for show and unchecked for hide...

V--- i need to make the check disappeer if the window is closed with the X but i always get the error:



the menu is in the main form but i need to change it from the child form...
i can use other functions in the unload event and not get an error message.

how can i get round this problem?

+ thanks alot for your replys! ^^;;
cloud- is offline   Reply With Quote
Old Aug 11th, 2005, 2:48 PM   #5
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
Unlike normal forms, I don't think child forms can access the MDI form they are in by name, so VB is trying to create a new instance for you, hence the error. Try accessing the Me.Parent object within the child form, or if not, declare a global boolean ChildFormVisible in a module somewhere. Or better still, move the code to the mnuView_Click or mnuView_Popup event, then you'd just need an If ChildForm.visible then somemenuitem.Checked=true line
Rory is offline   Reply With Quote
Old Aug 11th, 2005, 4:02 PM   #6
BrianN
Newbie
 
Join Date: Aug 2005
Posts: 6
Rep Power: 0 BrianN is on a distinguished road
well I have not been able to replicate your error message. Here is the code i tried.

My menu items were created using the menu editor provided in visual basic (not dynamically created at runtime)

First off the code for the menu items is like this:
Public Sub mnuform1_Click()
    If mnuform1.Checked = True Then
        Unload Form1
        mnuform1.Checked = False
    Else
        Load Form1
        mnuform1.Checked = True
    End If
End Sub
Take note to how i changed it from private to public

Next the unload code on the forms is like this:
Private Sub Form_Unload(Cancel As Integer)
     Call MDIForm1.mnuform1_Click
End Sub

Note when the program loads you are going to have to use the mdiform1.mnuform1.checked=true (or false) depending on what forms are shown to begin with.

I only spent about five minutes writing up this code, so I am sure that there are going to be several problems with it depending on what you are going to do with it. I can think of a few right now, but i won't go into details with them. (I am sure there are solutions to solving all of them)
BrianN is offline   Reply With Quote
Old Aug 11th, 2005, 4:39 PM   #7
cloud-
Hobbyist Programmer
 
Join Date: Jan 2005
Posts: 110
Rep Power: 4 cloud- is on a distinguished road
hey thanks rory but could you possibly give me a short example of how i can get something like you mentioned before, i don't quite understand how i can do that. i tryed making a function in a module...didnt work though all though maybe i misunderstood XD.
and im not sure what u meant by the 3rd solution...the menu click command can't take in to account the unload of the child form can it ?__?; because the problem is only the X button on the form.

please help
thanks
cloud- is offline   Reply With Quote
Old Aug 15th, 2005, 6:09 PM   #8
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
Quote:
Originally Posted by cloud-
hey thanks rory but could you possibly give me a short example of how i can get something like you mentioned before, i don't quite understand how i can do that. i tryed making a function in a module...didnt work though all though maybe i misunderstood XD.
and im not sure what u meant by the 3rd solution...the menu click command can't take in to account the unload of the child form can it ?__?; because the problem is only the X button on the form.

please help
thanks
Right, the problem is most likely accessing the checked property of a non-existent MDI form. Try approaching it from the other angle: if you had a menu called mnuView, the mnuView_Click() event fires before the menu is pulled down, giving you a change mnuView's appearence itself. So I'd suggest something along the lines of :
Private Sub mnuView_Click()
If Not (frmProjectWindow Is Nothing) Then ' Check if the form has been loaded
    If frmProjectWindow.Visible Then ' Check if the form is visible
        mnuViewProjectWindow.Checked = True ' Form is loaded and visible
    Else
        mnuViewProjectWindow.Checked = False
    End If
Else
    mnuViewProjectWindow.Checked = False
End If
End Sub
Rory is offline   Reply With Quote
Old Aug 19th, 2005, 5:24 AM   #9
cloud-
Hobbyist Programmer
 
Join Date: Jan 2005
Posts: 110
Rep Power: 4 cloud- is on a distinguished road
BrianN: sorry i didn't see your code before. I still go the error message by using that .

Rory: I tried that and when i click on the form menu it just makkes the form visible, and always stays checked.

thanks for helping guys.
any ideas to what im doing wrong?
cloud- is offline   Reply With Quote
Old Aug 23rd, 2005, 2:03 PM   #10
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
Quote:
Originally Posted by cloud-
Rory: I tried that and when i click on the form menu it just makkes the form visible, and always stays checked.
Really strange - could you upload the source code?
Rory is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:26 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC