Results 1 to 8 of 8

Thread: Listboxes

  1. #1
    j2k
    Guest

    Listboxes

    Hi. When a user right clicks a listbox, a popup menu appears. To make the menu appear I use the following command

    Code:
    Private Sub AutoExecEnabled_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbRightButton Then
    PopupMenu mnuMenuOne
    End If
    End Sub
    If I left click the listbox, the entry that the mouse is over becomes selected. I would like the same to happen when the right mouse button is clicked, before the menu appears, but currently, the entry that the mouse is over only becomes selected when the left mouse button is clicked, not if either button is clicked.

    Thanks for any info on accomplishing the task would be appreciated.

  2. #2

  3. #3
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    This is Not 100% acurate...but its darn close
    it catches about 85 - 90% of the right clicks

    Code:
    Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim YPos As Integer, iOldFontSize As Integer
    iOldFontSize = Me.Font.Size
    Me.Font.Size = List1.Font.Size
    YPos = Y / Me.TextHeight("Xyz") + List1.TopIndex
    Me.Font.Size = iOldFontSize
    If YPos < List1.ListCount Then
    If Button = 2 Then
    List1.Selected(YPos) = True
    PopupMenu mnuMenuOne
    End If
    End If
    End Sub
    VBBrowser v2.2.4
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4
    Hyperactive Member techman2553's Avatar
    Join Date
    Mar 2001
    Location
    <- To your left.
    Posts
    362
    I thought about submitting that approach as a solution, but what happens when you scroll through the list items ???
    ----------

  5. #5
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    techman - it will still work fine.
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  6. #6
    Hyperactive Member techman2553's Avatar
    Join Date
    Mar 2001
    Location
    <- To your left.
    Posts
    362
    Sorry, I didn't see the TopIndex offset....Actually I didn't even realize that there was a TopIndex property !! (I use ListView much more then ListBox)

    Thanks !!
    ----------

  7. #7
    Megatron
    Guest
    Or use the LBITemFromPt API function.
    Code:
    Private Declare Function LBItemFromPt Lib "comctl32.dll" (ByVal hLB As Long, ByVal ptx As Integer, ByVal pty As Integer, ByVal bAutoScroll As Long) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    
    Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Dim nPos As Integer
        Dim PT As POINTAPI
            
        If Button = 2 Then
            GetCursorPos PT
            List1.Selected(LBItemFromPt(List1.hwnd, PT.X, PT.Y, 0)) = True
            PopupMenu mnu
        End If
    End Sub

  8. #8
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    Very Nice Megatron!

    Flawless!


    Thats a keeper
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

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