is it possible to set ToolTipText on each element of a listbox? I haven't found this to be an option but I thought I'd ask and see if I was overlooking something..
Printable View
is it possible to set ToolTipText on each element of a listbox? I haven't found this to be an option but I thought I'd ask and see if I was overlooking something..
You can make an array to hold all tooltips, and in the mouseover event put it to recognize which one its over, thats a bit hard but you have the y var from the event and topindex property from the list, so you only need to know what height each item are. This maybe you should experiment by your own using the textheight and the font to another object.
Actually, it is very easy to do. Here's an example:
Code:Option Explicit
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function LBItemFromPt Lib "comctl32.dll" (ByVal hwnd As Long, ByVal ptx As Long, ByVal pty As Long, ByVal bAutoScroll As Long) As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Sub Form_Load()
Dim i As Integer
For i = 1 To 10
List1.AddItem "Item" & i
Next
End Sub
Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim intCurItem As Long
Dim pt As POINTAPI
Dim strItem As String
'adjust to the expected values
pt.X = X \ Screen.TwipsPerPixelX
pt.Y = Y \ Screen.TwipsPerPixelY 'and map to the client coordinates
Call ClientToScreen(List1.hwnd, pt) 'get the item nearest the cursor
intCurItem = LBItemFromPt(List1.hwnd, pt.X, pt.Y, False)
If intCurItem > -1 Then
List1.ToolTipText = List1.List(intCurItem)
End If
End Sub
Wow, what happened to Coding Colors ?????
Does anybody know how to position the tooltip exactly above the listbox's item, so it lookes as if the text is completed by the tooltip?
Thanks Serge.. that looks like what I need. I was thinking along those lines but I didn't know how to get the item that the mouse was over. As far as the color.. I don't know.. I've never been able to get my posts to show the VB color. *shrug*
well, then it's not a tooltip then. Or is it? You can find the hwnd of the tooltib with findwindow and then move it with movewindow, i don't know if the tooltip is a hwnd at all..
Serge: The colors are gone yeah, but worse, it puts extra lines after each line. Also, How did u get a Guru with 2k posts?
kedaman, I've noticed that after the last update they made on the UBB, they lost coloring functionality.
As for number of posts, I've been an active member on this UBB since February 1999, so I guess that's how many posts I have sice then.
I Just put that code in there and it works like a champ. I was afraid that it wouldn't display the new tooltip when the mouse was moved (like you'd have to move off of the box and back on) but it updates as you move down the list. Thanks again.. exactly what I was looking for.