December 20th, 2010, 03:21 PM
x-y coords of MenuStrip item
I want to show a ContextMenuStrip beneath a MenuStrip item when that item is clicked. Stuff in the ContextMenuStrip changes dynamically. The ContextMenuStrip is used in a DataGridView. I don't want to duplicate the same items in the MenuStrip.
I can get the mouse coordinates OK, but I don't want that. I want to use the ContextMenuStrip show method referenced to a control. An item in the MenuStrip is not a control, but the entire MenuStrip is a control. If I can get the x-y position of the item in the MenuStrip I can show the ContextMenuStrip in the right place, and it will look just as if it was part of the MenuStrip.
My question is how to obtain the location of the MenuStrip item that's active. Thanks
December 20th, 2010, 03:37 PM
Re: x-y coords of MenuStrip item
I can make it work with the following code, but the menu item color doesn't match other menu items when clicked. It's the second item. I'll just duplicate all the contextmenu items in the menu.
Private Sub MenuEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuEdit.Click
Dim j As Integer = MenuStrip1.Items(0).Width + MenuStrip1.Padding.Left + MenuStrip1.Padding.Right
ContextMenuStrip1.Show(MenuStrip1, j, MenuEdit.Height)
Click Here to Expand Forum to Full Width