Results 1 to 7 of 7

Thread: mouse event(resolved)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    471

    mouse event(resolved)

    I am working on a vb.net program. I have a treeview control on a form. What I want to do is to pop up a menu when user selects a node by RIGHT MOUSE. How can I do this? thanks.
    Last edited by Palmtree; Mar 25th, 2004 at 11:11 AM.

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Maybe just attach a ContextMenu to your TreeControl?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    471
    thanks for your reply.

    Actually my question is more detail, how to use the contextMenu control to create my menu? after that, how to popup it?

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Paste a Context Menu to your form , and paste this code in the Mouse Up event of the treeview .

    VB Code:
    1. Private Sub TreeView1_MouseUp(ByVal sender As Object, ByVal e
    2. As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseUp
    3.         If e.Button = MouseButtons.Right Then
    4.            
    5.             If Not Me.TreeView1.GetNodeAt(New Point(e.X, e.Y)) Is Nothing Then
    6.                 Me.TreeView1.SelectedNode = Me.TreeView1.GetNodeAt(New Point(e.X, e.Y))
    7.                 Me.ContextMenu1.Show(Me.TreeView1, New Point(e.X, e.Y))
    8.             Else
    9.                 Me.TreeView1.SelectedNode = Nothing
    10.             End If
    11.  
    12.         End If
    13.     End Sub

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    471
    thanks for the sample code. it helps a lot.

    I guess first of all, I need create a popup menu. I drag a contextMenu control on my form, then I want to add "import" and "export" to it, how can do this?

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    You just need to fill in the context menuitems as it's main menuitems . Select the context menu control , when it's activated (in design time) ,you'll find it at the top of your form , then you can add items there .

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    471
    thanks again. I just figure out how it works. my form is too big and the menu editor was out of my sight. silly me.

Posting Permissions

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



Click Here to Expand Forum to Full Width