By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

ToolTip for ListBox-/ComboBox-Items

P: n/a
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
--
www.TimoSoft-Software.de
Stop software patents!
Nov 20 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
* Timo Kunze <TK*********@gmx.de> scripsit:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #2

P: n/a
Herfried K. Wagner [MVP] schrieb:
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
--
www.TimoSoft-Software.de
Stop software patents!
Nov 20 '05 #3

P: n/a
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
--
www.TimoSoft-Software.de
Stop software patents!
Nov 20 '05 #4

P: n/a
Timo,

* Timo Kunze <TK*********@gmx.de> scripsit:
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
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #5

P: n/a
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
--
www.TimoSoft-Software.de
Stop software patents!
Nov 20 '05 #6

P: n/a
Timo,

* Timo Kunze <TK*********@gmx.de> scripsit:
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>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #7

P: n/a
Herfried K. Wagner [MVP] schrieb:
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)?

http://www.timosoft-software.de/down...oxToolTip2.zip
Look for the TODO in CToolTipListBox.vb.
Maybe, you can make the combobox ownerdrawn and handle the 'DrawItem'
event to get the highlighted item.

I'll try it.

Timo
--
www.TimoSoft-Software.de
Stop software patents!
Nov 20 '05 #8

P: n/a
I implemented OwnerDraw and now it works in a satisfying way.

Here's the code:
http://www.timosoft-software.de/down...oxToolTip3.zip

Timo
--
www.TimoSoft-Software.de
Stop software patents!
Nov 20 '05 #9

P: n/a
* Timo Kunze <TK*********@gmx.de> scripsit:
I implemented OwnerDraw and now it works in a satisfying way.

Here's the code:
http://www.timosoft-software.de/down...oxToolTip3.zip


Thank you! Is it "by design" that the tooltip is shown /below/ the list
portion of the combobox?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #10

P: n/a
Herfried K. Wagner [MVP] schrieb:
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
--
www.TimoSoft-Software.de
Stop software patents!
Nov 20 '05 #11

P: n/a
* Timo Kunze <TK*********@gmx.de> scripsit:
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.


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

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.