You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

BillMak

Beginner

  • "BillMak" started this thread

Posts: 4

Date of registration: Sep 14th 2012

  • Send private message

1

Tuesday, May 13th 2014, 4:38pm

MDI Child Menu

Hi,

I create a menu for MDIForm1 as follow:


Public Sub Form_Load()

Dim myFileMenu As VBMenuGroup

myFileMenu = Me.MenuBar.createMenuGroup(Null, "File", "File", False)
Me.MenuBar.createMenu myFileMenu, "FileNew", "New"
Me.MenuBar.createMenu myFileMenu, "FileOpen", "Open"
Me.MenuBar.createMenu myFileMenu, "FileClose", "Close"
End Sub

I set the menubar for MDIChild1 as follow:

Public Sub Form_Load()
Me.setMenuBar MDIForm1.MenuBar
End Sub

Any one know how to make myFileMenu visible in MDIChild1?

Thanks

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

2

Tuesday, May 13th 2014, 10:45pm

Hey there,

hmm, I don't think that is a legit approach!

Quoted

An application can have only one MDIForm object but many MDI child forms. If an MDI child form has menus, the child form's menu bar automatically replaces the MDIForm object's menu bar when the MDI child form is active...

source: http://msdn.microsoft.com/en-us/library/…6(v=vs.60).aspx

The MDIForm holds the MDIFormChildren's Menus.
So whenever a MDIFormChild gets the focus you have to initialize the according Menu.
Have a look here:
http://www.jabaco.org/board/p21-create-j…bar.html#post21


Dani

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

3

Tuesday, May 13th 2014, 11:02pm

I almost forgot:
Before initializing a Child's menu call:

Jabaco Source

1
Me.MenuBar.Parent.removeAll()


to unload the previous menu!!


Dani

BillMak

Beginner

  • "BillMak" started this thread

Posts: 4

Date of registration: Sep 14th 2012

  • Send private message

4

Wednesday, May 14th 2014, 4:36pm

Thanks for the quick reply, Dani

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

5

Wednesday, May 14th 2014, 4:55pm

No problem...

Hey, if you play around with this please share your solution in this forum!

BillMak

Beginner

  • "BillMak" started this thread

Posts: 4

Date of registration: Sep 14th 2012

  • Send private message

6

Wednesday, May 14th 2014, 8:38pm

Hi Dani,

I sure will share my code as soon as I figure it out.

Thanks again

BillMak

Beginner

  • "BillMak" started this thread

Posts: 4

Date of registration: Sep 14th 2012

  • Send private message

7

Thursday, May 15th 2014, 5:27pm

Hi Dani,

I sure will share my code as soon as I figure it out.

Thanks again


Hi,

This is what I have so far, still not working the way I wanted it to be.

In MDIForm1:

Public Sub Form_Load()
Call CreateMainMenu()
End Sub

Public Sub createMainMenu()
'Remove the current menubar
Me.MenuBar.Parent.removeAll()

Dim myFileMenu As VBMenuGroup
myFileMenu = Me.MenuBar.createMenuGroup(Null, "File", "File")
Me.MenuBar.createMenu myFileMenu, "FileNew", "New"
Me.MenuBar.createMenu myFileMenu, "FileOpen", "Open"
Me.MenuBar.createMenu myFileMenu, "FileClose", "Close"
Me.MenuBar.createMenu myFileMenu, "FileExit", "Exit"
End Sub

Public Sub addChildMenu()
'Remove the current menubar
Me.MenuBar.Parent.removeAll()

Dim myFileMenu As VBMenuGroup
myFileMenu = Me.MenuBar.createMenuGroup(Null, "File", "File")
Me.MenuBar.createMenu myFileMenu, "FileNew", "New"
Me.MenuBar.createMenu myFileMenu, "FileOpen", "Open"
Me.MenuBar.createMenu myFileMenu, "FileClose", "Close"
Me.MenuBar.createMenu myFileMenu, "FileExit", "Exit"

Dim myEidtMenu As VBMenuGroup
myEidtMenu = Me.MenuBar.createMenuGroup(Null, "Edit", "Edit")
Me.MenuBar.createMenu myEidtMenu, "EditCopy", "Copy"
Me.MenuBar.createMenu myEidtMenu, "EditPaste", "Paste"
Me.MenuBar.createMenu myEidtMenu, "EditDelete", "Delete"
End Sub

Public Sub Form_MenuClick(MenuItem As VB#IMenuItem)
Select Case MenuItem.ControlID
Case "FileExit"
'Exit Application
Me.Close()
Call End
Case "FileOpen"
Call addChildMenu()
Dim f As New MDIChild1
f.Caption = "New MDIChild"
f.Show()
Case "FileNew"
Case "FileOpen"
' Case "FileClose"
' f.Close()
' Call createMainMenu()
' Call DoEvents()
End Select
End Sub

In MDIChild1:

Public Sub Form_MenuClick(MenuItem As VB#IMenuItem)
Select Case MenuItem.ControlID
Case "FileClose"
Call MDIForm1.createMainMenu()
Me.Close()
End Select
End Sub

But MDIChild1's Form_MenuClick event never fired. any suggestion?

Thanks

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

8

Friday, May 16th 2014, 8:20am

Hey there,

please start using the codeformatting ability, <JBC> button, of this board. It makes reading you posts a lot easier.

Do not process anything concerning the menu in any Form object other than the MDIForm1!

A rough outline:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Public Sub addChildMenu(MDIChildIndex As Integer)
   'Remove the current menubar
   Me.MenuBar.Parent.removeAll()
   Select Case MDIChildIndex
   Case 1
      Dim myFileMenu As VBMenuGroup
      myFileMenu = Me.MenuBar.createMenuGroup(Null, "File2", "File2")
      Me.MenuBar.createMenu myFileMenu, "FileNew", "New"
   End Select
End Sub

Public Sub Form_MenuClick(MenuItem As VB#IMenuItem)
   Debug.Print Me.ActiveForm.getClass.getName()
   Debug.Print "MDIChild1 is selected: " & MDIChild1.isSelected
   Debug.Print "MDIChild2 is selected: " & MDIChild2.isSelected
   
'   If MDIChild1.isSelected Then addChildMenu(1)  ... add Your code here ...
End Sub


Actually it would be a lot more elegant to use:

Jabaco Source

1
Public Sub Form_GotFocus()

and sort things out there but I just found a bug here! At least at my system that is.

I hope all of this will inspire you a bit...


Dani

Rate this thread
WoltLab Burning Board