Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Gurus*
Posted (edited)

The Tooltip component is a great way of extending your controls to add tooltips to them. However, it has no inbuilt capability for displaying balloon-style tooltips so I knocked up this example.

 

A Tooltip is a special window maintained by the component you put on your form. Windows takes care of the positioning and resizing of the window to give it that familiar look, but the Tooltip component has to create and maintain that window. It keeps track of its window internally, and here's where the nasty part comes in.

 

I use reflection to get a hold of the native window the Tooltip component keeps in a private field. Once I have that, I can then access its hwnd, and from there change its window style. The style we need to remove is WS_BORDER, because when that is combined with balloon tooltips great ugliness ensues. The styles we need to make sure are applied are TTS_BALLOON and TTS_NOPREFIX.

 

After using GetWindowLong and SetWindowLong to accomplish this change to the window style, that's it. All tooltips displayed from then on are shown with a balloon.

 

I've attacked a zip file containing a simple project. The large button has a tooltip, and pressing the smaller button invokes our code that forces subsequent tooltips to be balloons.

 

[edit] Removed ghost reference - thanks Derek [/edit]

balloon.zip

Edited by divil

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...