How do you refer to Menus from other forms?

Post

Posted
Rating:
#1 (In Topic #1279)
Regular
sergioabreu is in the usergroup ‘Regular’
How to access the menus from out of the main form?
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’

sergioabreu said

How to access the menus from out of the main form?

Right, that's not so easy as they are different to normal controls.

There are options..
If your menu's are made by code and not in the IDE and they have a global object pointer you can simple make it Public

Code (gambas)

  1.  
  2. Public MainMenu As Menu
  3.  
  4. Public Sub Form_Open()
  5.  
  6.   MainMenu = New Menu(Me)
  7.   ' Rest of menu creation code
  8.  
  9.  

Then outside the form you can access the pointer.

Code (gambas)

  1. Print FMain.MainMenu.Children.Count
  2.  

Otherwise you have to use the Window.Menus array property.
/comp/gb.qt4/window/menus - Gambas Documentation
All the forms visible and non-visible top level menus and then their children are accessible from there.

Code (gambas)

  1.  
  2.   For Each hMenu As Menu In FMain.Menus
  3.     Print hMenu.Name;; "has";; hMenu.Children.Count;; "children"
  4.   Next
  5.  
  6.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
sergioabreu is in the usergroup ‘Regular’
Very nice.
Online now: No Back to the top
1 guest and 0 members have just viewed this.