CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2010

    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

  2. #2
    Join Date
    Dec 2010

    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)
        End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

By using this site, you agree to the Privacy Policy