Thursday, February 4, 2010

Notify Icon Text vs BalloonTipText

I have a small application that shows a users ip address via a tool tip when it sits in their system tray. Everything is going fine until someone sends me a bug that there was a problem. Investigating this I find that the method I was using to display tool tips in the system menu is somewhat flawed. I was using a notify icon control to show the tool tips while in the system tray. This works but I was setting the Text property of the control like this:

// old way of setting text, with 64 character limit
this.notifyIcon1.Text = "Show me in the toolbar";

This works but only for up to 64 characters. When I was designing the application I was thinking about ip addresses using the v4 format not the v6 format. Sure enough v6 ip addresses kick out more then 64 characters a lot of the time. So the search was on and I found using the balloon text can show more data but is a wee bit harder to use. Balloon tool tips don't show automatically like the text does. You have to use the notify icons MouseMove event and call the ShowBalloonTip method of the notify icon. So the code below solved my issue:

// set the balloon tip text
this.notifyIcon1.BalloonTipText = "Some realy really really really really ................................ text";

// using the MouseMove event to show the balloon tool tip
private void notifyIcon1_MouseMove( object sender, MouseEventArgs e )
this.notifyIcon1.ShowBalloonTip( 10 );

So now when the user mouses over the icon while in the tray they get a very nice looking tool tip. The only issue is the balloon tool tip IS NOT supported on windows 95. An old OS to be sure but some folks are still running it.

1 comment: