I have a popup menu that I want to attach to multiple controls.
how do I tell which control called the popup menu so I can perform the correct action. I would like to do this in a single popup menu.
the use will be to clear the text property in that control so I think the best is to do this in a single sub from a single popup menu instead of repeating code. I just can't see how to find which control called the popup.
popup menu help
- BruceSteers
- Posts: 1578
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: popup menu help
How I do it....
Do not use the Controls PopupMenu property . do it all in the MouseUp event using the PopUp function and the menu tag
Do not use the Controls PopupMenu property . do it all in the MouseUp event using the PopUp function and the menu tag
Public Sub MyButton_MouseUp()
If Not Mouse.Right Then Return
Menu1.Tag = Last.Name
Menu1.PopUp(Mouse.ScreenX, Mouse.ScreenY)
End
Then when any command from the menu is used i just check Menu.Tag to see where it was clicked from.If at first you don't succeed , try doing something differently.
BruceS
BruceS
- cogier
- Site Admin
- Posts: 1127
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: popup menu help
I had a long thought about this and came up with one routine that could do what you want.
1/. Create a global variable e.g. sName
2/. Make the Group property of all the controls the same e.g. Ctrls
3/. Create a routine Public Sub Ctrls_Enter(). This will catch the mouse moving into any of the controls and change the name of the global variable.
The line Me.Text = sName will change the Form's Title as you pass the mouse over the controls, so you can see how this works.
1/. Create a global variable e.g. sName
2/. Make the Group property of all the controls the same e.g. Ctrls
3/. Create a routine Public Sub Ctrls_Enter(). This will catch the mouse moving into any of the controls and change the name of the global variable.
The line Me.Text = sName will change the Form's Title as you pass the mouse over the controls, so you can see how this works.
sName As String
Public Sub Ctrls_Enter()
sName = Last.name
' Me.Text = sName
End
Re: popup menu help
Thank you both. I am glad cogier had to think about it hard. It makes me feel better that the expert himself had to think. I combined both approaches.
I used the mouseup event to call the popup and a global variable that holds the name of the button. I put the code I used below in case others need it. the tilde ~ just means there is other code.
Public ButtonID as string = ""
~
~
~
Public Sub btnPIDFile_MouseUp()
If Not Mouse.Right Then Return
ButtonID = "PID"
mbtnMakeBlank.Popup
End
Public Sub mnuClearValue_Click()
Select Case ButtonID
Case "PID"
btnPIDFile.Text = "Click To Set"
End Select
ButtonID = ""
End
I used the mouseup event to call the popup and a global variable that holds the name of the button. I put the code I used below in case others need it. the tilde ~ just means there is other code.
Public ButtonID as string = ""
~
~
~
Public Sub btnPIDFile_MouseUp()
If Not Mouse.Right Then Return
ButtonID = "PID"
mbtnMakeBlank.Popup
End
Public Sub mnuClearValue_Click()
Select Case ButtonID
Case "PID"
btnPIDFile.Text = "Click To Set"
End Select
ButtonID = ""
End
- BruceSteers
- Posts: 1578
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: popup menu help
sadams54 wrote: ↑Wednesday 25th August 2021 8:34pm Thank you both. I am glad cogier had to think about it hard. It makes me feel better that the expert himself had to think. I combined both approaches.
I used the mouseup event to call the popup and a global variable that holds the name of the button. I put the code I used below in case others need it. the tilde ~ just means there is other code.
Public ButtonID as string = ""
~
~
~
Public Sub btnPIDFile_MouseUp()
If Not Mouse.Right Then Return
ButtonID = "PID"
mbtnMakeBlank.Popup
End
Public Sub mnuClearValue_Click()
Select Case ButtonID
Case "PID"
btnPIDFile.Text = "Click To Set"
End Select
ButtonID = ""
End
Happy to help
PS. I forgot...
just under
If Not Mouse.Right Then Return
you should put...
If Not Mouse.Inside(Last) Then Return
Then if the user pushes mouse down then moves away from the control before mouse up it will not trigger.
If at first you don't succeed , try doing something differently.
BruceS
BruceS