ToolTip for ListBox-/ComboBox-Items

  • Thread starter Thread starter Timo Kunze
  • Start date Start date
T

Timo Kunze

Hi!

If you move the mouse over an item that's part of a treeview and wider
than the treeview, a tooltip showing the full item text will be
displayed. I try to do this for ListBoxes and ComboBoxes.
For ListBoxes I got it working, but not for the ListBox part of
ComboBoxes. Do you know any sample code?

Thanks in advance!
Timo
 
* Timo Kunze said:
If you move the mouse over an item that's part of a treeview and wider
than the treeview, a tooltip showing the full item text will be
displayed. I try to do this for ListBoxes and ComboBoxes.

For ListBoxes I got it working, but not for the ListBox part of
ComboBoxes. Do you know any sample code?

Untested: Handle the combobox's 'WM_CTLCOLORLISTBOX' message. This message will be sent if the listbox part of the combobox is created. In the 'lParam' parameter you will receive the handle to the listbox part, then you can use the 'NativeWindow' class to handle the listbox part's events.
 
Herfried said:
Untested: Handle the combobox's 'WM_CTLCOLORLISTBOX' message. This message will be sent if the listbox part of the combobox is created. In the 'lParam' parameter you will receive the handle to the listbox part, then you can use the 'NativeWindow' class to handle the listbox part's events.

Hello Herfried,

the problem is not to get the listbox handle (I used the DropDown event
and the GetComboBoxInfo api method), but to use it for further
processing. 'NativeWindow' seems the way to go, but can I use the
ToolTip class for NativeWindows? It doesn't seem so - so the next step
probably is writing a custom ToolTip class. Hmmm, smells like work, but
that's life I guess...
I hope .net 2.0 will simplify customizing a ComboBox' list portion.

Thank you!
Timo
 
Okay, my ToolTip class is working now. However, there seems to be a hook
eating all messages that the ListBox portion would normally receive.
Neither the ListBox nor the ComboBox receive WM_MOUSEMOVE or any other
mouse message.
I'll set up my own mouse hook now. It's "funny": So much work for such a
small thing. :P

Timo
 
Timo,

* Timo Kunze said:
Okay, my ToolTip class is working now. However, there seems to be a
hook eating all messages that the ListBox portion would normally
receive. Neither the ListBox nor the ComboBox receive WM_MOUSEMOVE or
any other mouse message.

I am able to receive the 'WM_MOUSEMOVE' message for the listbox part
using this code (no cleanup code included yet):

\\\
Imports System.Runtime.InteropServices

Public Class ExtendedComboBox
Inherits System.Windows.Forms.ComboBox

Private Const WM_CTLCOLORLISTBOX As Int32 = &H134

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_CTLCOLORLISTBOX Then
Dim n As New Foo()
n.AssignHandle(m.LParam)
End If
MyBase.WndProc(m)
End Sub
End Class

Public Class Foo
Inherits System.Windows.Forms.NativeWindow

Private Const WM_MOUSEMOVE As Int32 = &H200

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_MOUSEMOVE Then
Debug.WriteLine("Foo the bar")
End If
MyBase.WndProc(m)
End Sub
End Class
///
 
Hmmm, well, this makes my mouse hook useless. :)

However, I got all the stuff almost working and have come to the
conclusion that giving the Combo's own listbox portion ToolTips probably
is impossible (at least it's easier to use a custom ListBox as dropdown
window). There're 2 big problems:
1) LB_ITEMFROMPOINT always returns 0 in the lower 16 Bit, so I've no
clue which item the cursor is over. Since it works for stand-alone
ListBoxes, I asume the ComboBox is eating this message.
2) The ToolTip gets displayed, but it's always covered by the listbox
portion. If I use SetWindowPos to change Z-order, the combobox will
immediately close up.

I'll try some things, but I'll probably take the other way and display
my own dropdown window.

Thanks for your help.
Timo
 
Timo,

* Timo Kunze said:
However, I got all the stuff almost working and have come to the
conclusion that giving the Combo's own listbox portion ToolTips
probably is impossible (at least it's easier to use a custom ListBox
as dropdown window). There're 2 big problems:

1) LB_ITEMFROMPOINT always returns 0 in the lower 16 Bit, so I've no
clue which item the cursor is over. Since it works for stand-alone
ListBoxes, I asume the ComboBox is eating this message.

Can you post the source code (if you still have it)?

Maybe, you can make the combobox ownerdrawn and handle the 'DrawItem'
event to get the highlighted item.
I'll try some things, but I'll probably take the other way and display
my own dropdown window.

<URL:http://vbaccelerator.com/article.asp?id=13309>
 
Herfried said:
Thank you! Is it "by design" that the tooltip is shown /below/ the list
portion of the combobox?
Yes. I did this, because there seems to be no way to display it in front
of the list portion. If you call SetWindowPos to change Z-order, the
ComboBox probably thinks (and actually it is right) that the user
switched to another window and hides the list portion.
So displaying the tooltip below the list is still better than having it
partially covered.

Timo
 
* Timo Kunze said:
Yes. I did this, because there seems to be no way to display it in
front of the list portion. If you call SetWindowPos to change Z-order,
the ComboBox probably thinks (and actually it is right) that the user
switched to another window and hides the list portion.

So displaying the tooltip below the list is still better than having
it partially covered.

I remember you mentioned this problem in a previous post. So, the
"cleanest" solution is maybe writing your own combobox control based on
the vbAccelerator sample, but this would be a lot of work too...
 
Back
Top