![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Jan 2005
Posts: 110
Rep Power: 4
![]() |
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 Only one MDI form allowed. anyone know how i can do this? thanks ![]() |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Aug 2005
Posts: 6
Rep Power: 0
![]() |
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? |
|
|
|
|
|
#3 |
|
Expert Programmer
|
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
![]() |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Jan 2005
Posts: 110
Rep Power: 4
![]() |
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! ^^;; |
|
|
|
|
|
#5 |
|
Expert Programmer
|
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
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Aug 2005
Posts: 6
Rep Power: 0
![]() |
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 SubNext the unload code on the forms is like this: Private Sub Form_Unload(Cancel As Integer)
Call MDIForm1.mnuform1_Click
End SubNote 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) |
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Jan 2005
Posts: 110
Rep Power: 4
![]() |
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 |
|
|
|
|
|
#8 | |
|
Expert Programmer
|
Quote:
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 |
|
|
|
|
|
|
#9 |
|
Hobbyist Programmer
Join Date: Jan 2005
Posts: 110
Rep Power: 4
![]() |
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? |
|
|
|
|
|
#10 | |
|
Expert Programmer
|
Quote:
![]() |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|