Create Multi Line ToolTip Windows

Tooltip windows are those little windows that pop up when you hold the cursor over an item on a window. VB allows you to create tooltips for any control by entering the text into a control's tooltip property.

Tooltips created this way always display their text as a single line regardless of how long the text is. Also, text formatting characters such as vbCrLf or vbTab are not evaluated and typically display as "||".

Shown here is how to get your text to span multiple lines and how to get text formatting characters to evaluate properly.

Create multi-line tooltip windows that evaluate text formatting characters.
Download Source Code


Creating multi-line tootips is accomplished by calling the CreateWindowEx API to create a new window with a class of TOOLTIPS_CLASS and a style of TTS_ALWAYSTIP. The tooltip window is owned by your form so that it is destroyed when the form is closed.

Setting the width of the window is done via the SendMessage command. A message is sent to the window which includes the desired text width in pixels. If the width value is -1 then no word wrapping is performed (tooltip text will be a single line) and text formatting characters will display as "||".

Setting the amount of time the tooltip window is visible for as well as the actual formatted text to display is also done by sending the appropriate messages to the window.

The new tooltip window must be associated with a control on your form. Once again, SendMessage is used along with a TOOLINFO structure. This structure contains the handle for the control, its container, the tooltip text, tooltip width,...

Accomplishing all of the above is really very straight forward and all of this functionality is wrapped in a tooltip class module that can be included and utilized in your program.


Download this project and run it. Move the cursor over the controls to view the custom tooltips.

About TheScarms
About TheScarms

Sample code
version info

If you use this code, please mention ""

Email this page

© Copyright 2024 TheScarms
Goto top of page