Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

Anybody looking for a graduate programmer (Midlands, England)?
Posted

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

Posted

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

Anybody looking for a graduate programmer (Midlands, England)?
  • Leaders
Posted
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.
[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...