bjwade62 Posted January 30, 2006 Posted January 30, 2006 Using the code below, I'm displaying a context menu item when the user right clicks the mouse over a listview. The problem is that the menu item appears in the top left corner of the screen. Not only is it not over the listview, it's not even over the form itself. It sits alone on the desktop in the upper left corner. Anyhelp? Private Sub lvwLeftList_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lvwLeftList.MouseDown If e.Button = Windows.Forms.MouseButtons.Right Then Me.cmnuStrip1.Show() End If End Sub Private Sub cmnuSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmnuSelectAll.Click Dim ListLeft As ListViewItem For Each ListLeft In lvwLeftList.Items ListLeft.Selected = True Next End Sub Quote
Cags Posted January 30, 2006 Posted January 30, 2006 Well I'm slightly confused by your code, assuming that cmnuStrip1 is a ContextMenu object of some kind. Since in my Visual Studio this only has one overload for the Show() method, and that requires a control and a position I can only assume you have a newer version or are using a different control (perhaps a .Net 2.0 control). Once a context menu is added as a component to the form I would show it like so.... ' assuming cmnuStrip1 is a context menu like so Dim cmnuStrip1 as new ContextMenu() ' show the context menu at a point slightly offset from the control cmnuStrip1.Show(lvwLeftList, new Point(10, 10)) Quote Anybody looking for a graduate programmer (Midlands, England)?
bjwade62 Posted January 30, 2006 Author Posted January 30, 2006 Thanks. Can it be located near the current cursor location somhow? Well I'm slightly confused by your code, assuming that cmnuStrip1 is a ContextMenu object of some kind. Since in my Visual Studio this only has one overload for the Show() method, and that requires a control and a position I can only assume you have a newer version or are using a different control (perhaps a .Net 2.0 control). Once a context menu is added as a component to the form I would show it like so.... ' assuming cmnuStrip1 is a context menu like so Dim cmnuStrip1 as new ContextMenu() ' show the context menu at a point slightly offset from the control cmnuStrip1.Show(lvwLeftList, new Point(10, 10)) Quote
Cags Posted January 30, 2006 Posted January 30, 2006 This should do the trick, might not be the best way but it's the only way I could come up with off the top of my head. Dim tmpPoint As Point = PointToClient(MousePosition) cmnuStrip1.Show(lvwLeftList, New Point(tmpPoint.X - Button1.Left, tmpPoint.Y - Button1.Top)) Quote Anybody looking for a graduate programmer (Midlands, England)?
Leaders snarfblam Posted January 31, 2006 Leaders Posted January 31, 2006 A context menu strip (.Net 2.0) and a context menu (.Net 1.0+) are two different components (one uses Window's built in menus while the other uses a customized Office style menu). Though they perform the same function, you should be aware that there may be differences between their interfaces. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.