Intercettare selezione di sotto-voci di un Menu

Da Gambas-it.org - Wikipedia.

Per intercettare la sola e semplice selezione delle sotto-voci di un Menu, ossia quando (senza cliccare sul mouse) si scorre con il puntatore del mouse al di sopra degli item di una voce principale di Menu, è possibile utilizzare un codice come il seguente:

Private Menu2 As Menu
Private Menu3 As Menu
Private Menu4 As Menu
Private tm As Timer


Public Sub Form_Open()
 
 Dim Menu1 As Menu

 With Menu1 = New Menu(Me) As "Menu1"
   .Caption = "Menu1"
 End With
 With Menu2 = New Menu(Menu1)
   .Caption = "Menu2"
   .Tag = "Questo è il Menu2 !"
 End With
 With Menu3 = New Menu(Menu1)
   .Caption = "Menu3"
   .Tag = "Questo è il Menu3 !"
 End With
 With Menu4 = New Menu(Menu1)
   .Caption = "Menu4"
   .Tag = "Questo è il Menu4 !"
 End With
 
End


Public Sub Menu1_Show()
 
 With tm = New Timer As "Tempus"
   .Delay = 20
   .Start
 End With
  
End


Public Sub Tempus_Timer()

 Dim rt2 As New Rect(Me.ScreenX + 10, Me.ScreenY + 26, Me.Font.TextWidth(Menu2.Caption) + 20, Me.Font.TextHeight(Menu2.Caption))
 Dim rt3 As New Rect(Me.ScreenX + 10, Me.ScreenY + 50, Me.Font.TextWidth(Menu3.Caption) + 20, Me.Font.TextHeight(Menu3.Caption))
 Dim rt4 As New Rect(Me.ScreenX + 10, Me.ScreenY + 72, Me.Font.TextWidth(Menu4.Caption) + 20, Me.Font.TextHeight(Menu4.Caption))

 Me.Title = Null
 If rt2.Contains(Mouse.ScreenX, Mouse.ScreenY) Then Me.Title = Menu2.Tag
 If rt3.Contains(Mouse.ScreenX, Mouse.ScreenY) Then Me.Title = Menu3.Tag
 If rt4.Contains(Mouse.ScreenX, Mouse.ScreenY) Then Me.Title = Menu4.Tag

End


Public Sub Menu1_Hide()
 
 tm.Stop
 
End