Click here to Skip to main content
Click here to Skip to main content

Balloon Tips Galore!

By , 14 Sep 2003
 

Introduction

This article introduces creating Balloon Tooltips, using available standard APIs. Balloon Tooltips can be very useful sometimes, however if used improperly can be painful for the user. Simply put, the code creates different types of balloon Tooltips. To use this, download the code, and choose the class you want to add in your project. Copy it over to your solution and you are ready to go. Have a look at the code behind the forms (Form1, Form2, Form3) in order to use it. The aim here was to keep the code as simple and modular as possible.

There are quite a few excellent articles on Code Project explaining how to create BalloonTips. Some even create them from scratch and are probably more feature rich. While I found these articles very informative, I also felt the need to use the original tips which come with Windows XP. The result is this simple API based project. Most of the code is based on this MSDN article.

I have omitted a notification kind of Tooltip or a Task Tray kind of balloon tip, just because there is already a good example on Code Project.

Using the code

All classes contain explanatory doc comments where necessary. Also code has been provided in both VB and C# to help ease of usage. The solution has been created in VS. NET 2003, hence may not be usable from VS. NET 2002, However the source code shouldn't be a problem.

HoverBalloon: Instead of showing a Tooltip over a control, a balloon tip can be shown over the control. Use this in cases where you want to attract the user's attention to detail. Use this sparingly in your application, so that user doesn't end up seeing a festival of balloons scattered over the form.

MessageBalloon: Has more control over the display of the balloon. The stem, location of the balloon can be changed with this class. This can be shown and hidden at will. Use this whenever you need a non-modal message box.

EditBalloon: Notice how a balloon comes up while entering the password in a edit control, if the CAPS lock is pressed accidentally ? It just reminds the user, but doesn't stop the process. Use this class as a reminder to the user while entering key edit fields.

If using VS. NET 2002 then a manifest file needs to be added to the directory in which the binary resides. (Find one in the 'bin' directory of download). If using VS. NET 2003 then Application.EnableVisualStyles() needs to be called before any form is loaded.

Enjoy the code, any feedback is appreciated.

Points

If the user has disabled BalloonTips in the registry then this probably wont work. This hasn't been tested on operating systems other than XP, so probably it won't work there.

Future Improvements

Provide designer support similar to the Tooltip control, by deriving from System.ComponentModel.Component class, similar to the System.Windows.Forms.ToolTip class at design time.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Ramesh Shrivastav
Web Developer
United States United States
Ramesh is very much into Microsoft technologies, and silently marvels at the power of Windows SDK.
He juggles his time between his family, work and his computer.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionLicencememberDommett16-May-13 0:01 
Can the op please update the licence information on the article to confirm it as assumed (CPOL) or other as required. I'm unable to use it unless the licence is explicitly defined.
QuestionIt is getting crashed everytime on startup of the program in win7membergaurish thakkar18-Jan-13 0:58 
it causes the program to crash with error ...unhanded exception to write protected memory
Microsoft Certified Technology Specialist

QuestionRightToLeft Supportmembercearsh11-May-12 21:47 
how add RightToLeft Support to Ballon? Sigh | :sigh:
GeneralMy vote of 5membermanoj kumar choubey23-Mar-12 4:01 
Nice
GeneralMy vote of 5memberjtxd5-May-11 22:05 
Perfect work!!!
 
In my project, I add a property named 'HideOnLeave' to this control.
In the end of method 'Show()', if 'HideOnLeave' is true, I bind 'LostFocus' and 'Disposed' events to the parent-control. And then Remove the events in it.
 
And also, I expect to know how to get this feature: under title is empty, the text is not empty and the icon is not none. Show the icon with text in the same line without being bold.

modified on Thursday, May 19, 2011 2:50 AM

GeneralMy vote of 5memberraiserle7-Apr-11 9:39 
perfect
QuestionHow to show the balloon tooltip using the TTM_POPUP messagememberfeg200027-Aug-10 10:17 
I tried to display the balloon tooltip progammtically by sending message to it with TTM_POPUP - SendMessage(m_tool.Handle, TTM_POPUP, 0, 0), but it didn't work.
Any suggestions? Thanks.
Questionhow to disable windows' balloonmemberHZ216-Dec-09 2:43 
hi,
 
I'm using this code (FMSEditTip.vb) and it works fine. I have only one problem: I have textbox1 on form1. UseSystemPasswordChar=true for textbox1 because it is a password field. When I write in this textbox and caps lock is on always appears the windows warning balloon. I want to disable system's balloon and use mine instead.
 
I copied the code in my project and my balloon appears properly when caps lock is on. Windows' balloon also appears so I have 2 balloons at the same time. So how to disable windows' balloon??
GeneralCrash on Windows 7 (64bit)memberMember 344021116-Dec-09 0:47 
I am using windows 7 64bit when I run this project, before tooltip would appear it simply crashes every time.
 
any fixes?
AnswerRe: Crash on Windows 7 (64bit)memberHZ216-Dec-09 2:54 
I also use this code on W7 64bit, and works fine!
Have you got any error messages?
GeneralRe: Crash on Windows 7 (64bit)memberAlex Casamassima8-Jan-10 4:09 
I get the same error, when running in 64bit Vista or Windows 7. (same code works great in 32bit)
 
There is no Debug information that i can find useful because it crashes the process from the system and doesn't get caught by .net at any level Frown | :( and i can't figure out o/s debug information for the life of me, but i can tell you at what line of code it crashes on:
Inside FMSMessageTip:

        Private Sub Display(ByVal show As Integer)
            Dim ptrStruct As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ti))
 
            Marshal.StructureToPtr(ti, ptrStruct, True) 'CRASHES RIGHT HERE!!!!!!!!!!

            SendMessage(m_tool.Handle, TTM_TRACKACTIVATE, show, ptrStruct)
            Marshal.FreeHGlobal(ptrStruct) 'CRASHES
        End Sub
 
I know very very little on how "Marshal" works, perhaps the Allocated memory size needs to be bigger? Any help would be greatly appreciated Smile | :) why would a 32 bit application work vs a 64bit application.
 
HACKED FIX
Project Settings -> Compile Options -> Advanced Compile Options... -> Target CPU x86
 
This will treat the program as 32bit program, and the bubbles appear without a problem! However, i would prefer keeping my program operating as a 64 bit program when on a 64bit machine. So if anyone can kindly make suggestions or provide a solution i would greately appreciate it!!!!!
 
Thanks Smile | :)
GeneralRe: Crash on Windows 7 (64bit)memberHimal1619813-Jun-10 5:36 
http://blogs.msdn.com/b/dsvc/archive/2009/11/02/p-invoke-marshal-structuretoptr.aspx[^]
GeneralAnother ThanksmemberGary Huckabone8-Dec-09 9:37 
Thanks! Been looking for a useful [working] example - this one works with VS 2008!
GeneralThanksmemberoldsellerros30-Nov-09 3:30 
Verry usefull and easy to understand! thanks you mateRose | [Rose]
Generalensure message balloon dies when window changes or closesmemberBobishKindaGuy9-Apr-09 11:53 
The MessageBalloon has the potential to stay put until you close it or the user closes it. That is good for longer messages.
 
Problem: If the user activates another app or clicks Next on a Wizard, the MessageBalloon stays right there, but now it's pointing at something else!
 
I know the HoverBalloon could be used, since it is built to kill itself after x seconds, but in that case, the programmer is trying to guess how fast the user can read!! For longer messages, the user is reading the message when it disappears. Not appropriate.
 
So, I've used a module-level variable to hold the ref to the MessageBalloon, so that when the user does something like bring another app to the front, I can kill the MessageBalloon. Unfortunately, I have to put code everywhere to kill the MessageBalloon, such as in the FormClosing event, or in other button_click events, etc. etc.
 
Has anyone found a better way to ensure that the MessageBalloon gets closed when the control it is pointing at becomes obscured or another app gets focus?
AnswerRe: ensure message balloon dies when window changes or closes [modified]memberKPEBEDKO13-Aug-09 22:23 
I suggest you looking into parent form events.
 
        public MessageBalloon(Control parent)
        {
            m_parent = parent;
            m_tool = new MessageTool();
            m_tool.DeActivate += new DeActivateEventHandler(this.Hide);
 
            Form parentForm = parent.FindForm();
            parentForm.Deactivate += new EventHandler(ParentFormDeactivate_EventHandler);
            parentForm.HandleDestroyed += new EventHandler(ParentFormDeactivate_EventHandler);
        }
 
        private void ParentFormDeactivate_EventHandler(object sender, EventArgs e)
        {
            Hide();
        }

 
modified on Wednesday, August 19, 2009 9:33 AM

GeneralHoverBalloon disappears rather quicklymemberBobishKindaGuy4-Jan-09 0:37 
Looking at the code for the HoverBalloon, I don't see any clear way of setting the timeout for it to disappear. If the text is a bit longer, the user won't have time to read it before it's gone.
 
________
42 is definitely not the meaning of life.
I knew that when I turned 43.

GeneralRe: HoverBalloon disappears rather quicklymembersgennette9-Apr-09 8:54 
Here's what I found that did work for setting the ballon duration to 10 seconds:
 
public const int TTM_SETDELAYTIME = (WM_USER + 3);
public const int TTDT_AUTOPOP = 2;
 
[DllImport("User32", EntryPoint = "SendMessageA", SetLastError = true)]
public static extern int SendMessage(
IntPtr hWnd,
int Msg,
long wParam,
long lParam);
 
SendMessage(
m_tool.Handle,
TTM_SETDELAYTIME,
TTDT_AUTOPOP, 10000);
GeneralRe: HoverBalloon disappears rather quickly [modified]memberBobishKindaGuy9-Apr-09 10:48 
Thanks, sgennette,
 
I'm having a bit of trouble implementing your suggestion, can you show where you put the "SendMessage" call to implement this?
GeneralRe: HoverBalloon disappears rather quicklymembersgennette10-Apr-09 3:06 
I put the code here;
 
Marshal.FreeHGlobal(ptrStruct);
 
SendMessage(
m_tool.Handle,
TTM_SETMAXTIPWIDTH,
0,
new IntPtr(m_maxWidth));
 
SendMessage(
m_tool.Handle,
TTM_SETDELAYTIME,
TTDT_AUTOPOP, 15000);
 
I'm still trying to understand these messages and where they should go. I have two labels that I'm using for the hover balloons and I can get one to work well but not both. Gotta figure it out.
GeneralRe: HoverBalloon disappears rather quicklymemberBobishKindaGuy10-Apr-09 9:15 
I program in VB, and have used this project as a basis for a VB project.
 
When I include the code you have posted above, the HoverBalloon appears but disappears almost instantly.
 
Would you be inclined to have a look at my project and see if you can determine why this is? If so, please send me your email address to bobishkindaguy@hotmail.com and I'll send you a zip of the code.
 
Or if you prefer, please send me a zip of your working sample and I'll convert it to VB and see where mine differs.
 
Thanks very much.
Bob
GeneralBalloonTip Visual Stype & WPFmemberRStern26-Aug-08 0:15 
Hey,
First - excellent post!
Second, while I managed to run the code from a WPF application and everything works, I see the balloon with no visual styles (and no X button as well).
 
Do you know how can I overcome this?
Thanks!
 
--sternr
QuestionHow to do it for richtextbox?memberPriyank Bolia10-Apr-08 9:29 
How to do it for richtextbox, rather than normal textbox.
 

GeneralHelp with edit tooltipmemberrageit15-Jul-07 19:22 
This is a good control.
However, I need to show the tooltip when user enters invalid data in a control. The best option for me would be edit tooltip. But when the control's validating event is cancelled, other controls are still working. Note that I have placed my control in a tab page. Its buttons are unexpectedly firing their events, but the tab pages and the form's close button are not working which is a desired behavior.
Any clue!
GeneralEdit ToolTip Appears and dissapearsmemberCarl Ja23-May-07 13:52 
I am using the a command button to trigger the show method of the edit tool tip. However the tooltip quickly appears and dissapears.
 
However, if i invoke the CommandButtun_Click even from the main menu the tooltip stays.
 
Any ideas?

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130617.1 | Last Updated 15 Sep 2003
Article Copyright 2003 by Ramesh Shrivastav
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid