how to detect which menu item was clicked

Post

Posted
Rating:
#1 (In Topic #1262)
Regular
bill-lancaster is in the usergroup ‘Regular’
 Is it possible to identify the last menu item clicked?
I have a project with many menu items and would like to store the last menu item clicked, or the last form opened via the menu system.
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Administrator
sholzy is in the usergroup ‘unknown’
 You can use "Last.xxxx". xxxx = "Name", "Group", "Caption", "Tag". I don't know if "Action" would work as I've never used that when creating menus.

sholzy
Gambas One Site Director

To report bugs in the Gambas IDE:
Official Gambas Bug Tracker
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
vuott is in the usergroup ‘Regular’
…interpreting Got2BeFree's good suggestion:

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.   Dim Menu1, Menu2, Menu3, Menu4 As Menu
  4.  
  5.   With Menu1 = New Menu(Me)
  6.     .Caption = "Menu1"
  7.  
  8.   With Menu2 = New Menu(Menu1) As "Mn"
  9.     .Caption = "Menu2"
  10.   With Menu3 = New Menu(Menu1) As "Mn"
  11.     .Caption = "Menu3"
  12.   With Menu4 = New Menu(Menu1) As "Mn"
  13.     .Caption = "Menu4"
  14.  
  15.  
  16.  
  17. Public Sub Mn_Click()
  18.  
  19.   Print Last.Caption
  20.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
bill-lancaster is in the usergroup ‘Regular’
 I guess the only way to generate a general menu event is by creating the menu items from code.
Thank you both, this works fine.
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
it work with my Main.form menu editor generated menus
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Administrator
sholzy is in the usergroup ‘unknown’

bill-lancaster said

I guess the only way to generate a general menu event is by creating the menu items from code.
Thank you both, this works fine.

Also works when using the menu GUI to create menus.

sholzy
Gambas One Site Director

To report bugs in the Gambas IDE:
Official Gambas Bug Tracker
Online now: No Back to the top

Post

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

bill-lancaster said

I guess the only way to generate a general menu event is by creating the menu items from code.
Thank you both, this works fine.

No you can use the IDE menu editor. You just make all the menus the same "Group" then the group name becomes the event name for all of them.
Online now: No Back to the top

Post

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

Got2BeFree said

You can use "Last.xxxx". xxxx = "Name", "Group", "Caption", "Tag". I don't know if "Action" would work as I've never used that when creating menus.

To explain the Action property a bit…..

If you use an action name , say "MyAction" you can then do various things, depending on your needs.

Like grouping objects together, for example a bunch of controls all related to something that might want disabling easily.
You could then do the following if you have a bunch of controls with the Action set to MyAction…

Action["MyAction"].Enabled = False

That would make all MyAction items disabled.
see /comp/gb.qt4/action - Gambas Documentation for other settable action properties

To use the Action property in a similar way to the above Group/Shared event use you must use the Action_Activate(Name As String) event in your form.  (although I don't think this is what the OP wants it's good to know)
For example..

Code (gambas)

  1.  
  2. Public Sub Action_Activate(sName As String) As Variant
  3.  
  4.   Select sName
  5.   Case "MyAction"
  6.     ' Do this action.
  7.  
  8.  

That way all objects with MyAction action set will use the same code.

There's a few other reasons tat Action comes in handy, mostly i use it do disable/enable various things that don't have the same parent.

Hope that helps :)
Online now: No Back to the top

Post

Posted
Rating:
#9
Regular
bill-lancaster is in the usergroup ‘Regular’
 Glad I asked the question, have learned a lot although I should have thought about the group_event idea, I use it in other situations!
Thanks for the many reponses.
Bill
Online now: No Back to the top
1 guest and 0 members have just viewed this.