I have the following code and when it fires from right click, the globals ObjectWithMouseOver = -1 and ObjectWithSelection = -1.
Why do I still get a contextual menu with a Delete menu item?
Function ConstructContextualMenu(base as MenuItem, x as Integer, y as Integer) As Boolean
if ObjectWithMouseOver > -1 and ObjectWithSelection > -1 then
base.Append(New MenuItem("Delete"))
else
return false
end if
Return True
End Function
Breakpoint in. Context menu still popping up and execution is not stopping at the break point.
The values have been greater than -1 to initially popup the menu as it should. I then click away from one of my objects and ObjectWithMouseOver = -1 and ObjectWithSelection = -1 and I have checked this with MsgBox just above the code shown. In fact, i’ll uncomment the MsgBox code you see in the image above, see below:
Uh… Are you sure that the menu is being created here? Do you maybe have something in the MouseDown event that creates a menuitem and then shows it with the .popup method?
Function ConstructContextualMenu(base as MenuItem, x as Integer, y as Integer) As Boolean
If x > 100 Then
base.Append(New MenuItem("x-position: " + Str(x)))
Else
Me.AddRow("x-position:" + Str(x))
End
Return True
End Function
I would expect Base to be a new menuItem created when the event is raised, but I’d be wrong.
Please sign on to the bug and maybe it will get fixed soon!
Not waiting anymore, I have created a new class and put it on GitHub to do contextual menus. My class effectively resets ‘base’ after the event is raised. It has 2 methods and 1 event, real easy to use…
[quote=113964:@jim mckay]I would expect Base to be a new menuItem created when the event is raised, but I’d be wrong.
Please sign on to the bug and maybe it will get fixed soon! ;)[/quote]
Jim, I have signed on
Here’s a simpler way to workaround than what’s in the feedback case…
[code]Function ConstructContextualMenu(base as MenuItem, x as Integer, y as Integer) As Boolean
Static lastBase as MenuItem=base
while lastbase.Count>0
lastbase.Remove(0)
wend
lastBase=base
//Normal code to show the menu or not…
End Function
[/code]
As far as I can tell the rectControl class must have a contextualMenu property that gets replaced with the new base menu, but if the base has no items, the old menu is not replaced and hence, the old menu is shown again
Try this code in a canvas…
static count as integer=1
if x<100 then
base.Append new MenuItem("Click #"+str(count))
end if
count=count+1
Return true