Context menu position

G

Guest

I have a tree view to which a context menu strip has been assigned.

When the user right clicks the first time on a tree node in the tree view to
show the context menu, it always shows at a position near the top of the tree
view control, not at the tree node where the user is right-clicking.

Once the menu has been shown one time, it will then display at the location
of the tree node where the user is right-clicking.

I have tried various arguments to context menu's Show() method, trying to
force display at a specific location, but I haven't been able to determine
what the screen coordinates are for the selected tree node.

Any ideas?
 
G

Guest

I have tried various arguments to context menu's Show() method, trying to
force display at a specific location, but I haven't been able to determine
what the screen coordinates are for the selected tree node.

When I show a context menu, I do it like this:

dim cm as ContextMenu
dim MyControl as Control ' may also be a form
...
cm.Show(MyControl, MyControl.PointToClient(Control.MousePosition()))

In my case, I always want the cm to display near the mouse when the user
right clicks. It took some effort to get this straight, the problem being
getting the coordinates right (eg 0,0 is relative to what?). In my uses,
MyControl is a form rather than a control on the form, but in theory, it
should work in both cases. Maybe a variant of this will help you.

FYI, in my case, cm is constructed at runtime, it is used, and then it is
discarded. Throughout, MyControl.ContextMenu is Nothing, ie I never do
MyControl.ContextMenu=cm. If you do different, then the experiment lacks
control. If it works, fine, but if it fails, I won't know what to conclude.

Good luck.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top