Dynamic menu help please

Hello,

I have this code in a TextField for a dynamic menu…

// Make the base item, this is what will be doing the popping up
dim base as new MenuItem

// Add some hard-coded items
base.Append(new MenuItem(“1”))
base.Append(new MenuItem(“2”))
base.Append(new MenuItem(“3”))
base.Append(new MenuItem(“4”))
base.Append(new MenuItem(“5”))

// Add a Separator
base.Append( new MenuItem( MenuItem.TextSeparator))

// Now display the menu
dim hitItem as MenuItem
hitItem = base.PopUp
if hitItem <> nil then me.Text = hitItem.Text

Return True

… it works great.

The problem I am having is that if I should click on the TextField the menu would show as expected, if I now move the mouse to another location and do a very quick MouseUp-MouseDown the menu is now shown at the new location of the mouse.

Even if I move the mouse to another location where another dynamic menu is located and do a very quick MouseUp-MouseDown the first menu is now shown at the new location of the mouse.

How could I prevent that from happening?

Thanks.

Lennox

What event handler is this code in?
Window.MouseDown?
TextField.MouseDown?

Hi Tim,
It is in the TextField.MouseDown
Lennox

Hard to say since its not clear what you expect
http://documentation.xojo.com/index.php/MenuItem.Popup
Popup will, without an X & Y parameter, pop the menu up where the mouse is
If you don’t want that then you will want to say where to show the menu - but I have no idea what position that might be

Hi Norman,

The menu shows up as expected. When I click on the EditField the menu shows at the point of the mouse-click - no problem there.

The problem I am having is that if I should click on the TextField the menu would show as expected, if I now move the mouse to another location, (while that menu is being displayed), and do a very quick MouseUp-MouseDown the menu is now shown at the new location of the mouse.

Even if I move the mouse to another location, (while that menu is being displayed), where another dynamic menu may be located and do a very quick MouseUp-MouseDown the first menu is now shown at the new location of the mouse.

Lennox

Based on your description of your code, where the event handlers are etc your code is doing exactly what you told it to

[quote=87348:@Lennox Jacob]hitItem = base.PopUp
[/quote]

http://documentation.xojo.com/index.php/MenuItem.Popup
Popup will, without an X & Y parameter, pop the menu up where the mouse is
To NOT do that you have to supply the X & Y but I don’t know what you DO want for those values

You may want to check if they’re in the TextField before telling the menu to pop up.
If they’re not return false or something. The user will click again - they always do :wink:

Thanks Norman and Tim,

I think I get the drift now.
this seems to be working the way I want it to work…
// Make the base item, this is what will be doing the popping up
dim base as new MenuItem

// Add some items
'Add some hard-coded items
base.Append(new MenuItem(“1”))
base.Append(new MenuItem(“2”))
base.Append(new MenuItem(“3”))
base.Append(new MenuItem(“4”))
base.Append(new MenuItem(“5”))

'// Add a Separator
base.Append( new MenuItem( MenuItem.TextSeparator))

// Now display the menu
dim hitItem as MenuItem
If (X > 0 and x < me.Width) and (Y > 0 and Y < Me.Height) then

hitItem = base.PopUp
if hitItem <> nil then me.Text = hitItem.Text

else

end if

Return True

Thanks again.

Lennox