Click here to Skip to main content
14,491,274 members

Balloon Windows for .NET

Rate this:
4.50 (23 votes)
Please Sign up or sign in to vote.
4.50 (23 votes)
2 Aug 2002CPOL
A class that allows for balloon shaped forms in .NET

Image 1

Image 2


This is a .NET version of Joshua Heyer's Balloon Help. Intially, I started with building a .NET wrapper on Josh's C++ code but soon I realized that there are advantages of rewriting everything from scratch in C#. The primary advantage was designer support - the windows form designer actually shows the balloon shape in the window (as seen in the screen shot below).

Image 3

In your project you can, either:-

  1. Use a form inherted from BalloonWindow. This is useful if you want to add your own controls to the balloon window.
  2. Use BalloonHelp class. This provides a balloon with a caption, content, icon and a close button. This is functionally similar to Josh's original balloon help

Using BalloonWindow Class

If you want to create your own balloon shaped windows, you can inherit from this class. In VS.NET you can do it by adding and Inherited Form item to the project as shown below:-

Image 4

Next, select BalloonWindow as the base class for your form, in the Inheritance picker dialog shown by VS.NET.

Image 5

This will bring up a balloon shaped form in the designer and now you can design the form as any other form. The windows form designer actually shows the balloon window. This is something which was never available in any designer - either the resource dialog editor of VC6 or the VB6 forms designer.

The only important property in BalloonWindow class is the

property. This is where the tail of the balloon is anchored to. This point is always in screen coordinates. This property can be set either at the design time or at runtime before or after the balloon is displayed. Setting this property after the balloon is displayed automatically moves the balloon window to a new anchor point. The following code snippet shows to anchor the balloon to point (100, 100):-

//My balloon form is a class derived from BallonnWindow
MyBalloonForm form = new MyBalloonForm(); 

form.AnchorPoint = new Point(100, 100);

A static method AnchorPointFromControl is provided that calculates the screen coordinates of the center point of a control. The BalloonWindow class also provides a a ShowBalloon method that uses

internally to display the balloon anchored to a control. Example:-

MyBalloonForm form = new MyBalloonForm(); 
form.ShowBalloon(textbox1); //Balloon will be anchored to textbox1

Using the BalloonHelp Class

The BalloonHelp class provides functionality of Josh's original C++ balloon help class. This class has following additional properties:-

  1. Caption: string
    This specifies the text of the balloon caption. This is same as the Text property of base class System.Windows.Forms.Control.
  2. CaptionFont: System.Drawing.Font
    Specifies the font of the balloon caption. If this is not specified a bold variety of the Font property is used.
  3. Content: string
    Specifies the text of the balloon contents.
  4. Font: System.Drawing.Font
    The Font property is inherited from System.Windows.Forms.Control. It specifes the font to be used for drawing the contents.
  5. ShowCloseButton: bool
    Indicates whether or not to show a close button on the top right corner of the balloon. The deafult value is false.
  6. CloseOnDeactivate: bool
    If this property is set to true the balloon window will close when the user switches to a different application. The deafult value is true.
  7. CloseOnMouseMove: bool
    If this property is set to true the balloon window will close when the mouse is moved. The deafult value is false.
  8. CloseOnMouseClick: bool
    If this property is set to true the balloon window will close when any mouse button is clicked. The deafult value is true.
  9. CloseOnKeyPress: bool
    If property is set to true the balloon window will close when a key is pressed on the keyboard. The deafult value is true.
  10. EnableTimeout: bool
    Sometimes, it may be required that the balloon close itself after a particular interval. It will happen if this property is set to true. The deafult value is false.
  11. Timeout: int
    This specifies the interval in milliseconds after which the balloon will close itself. The deafult value is 5000.
  12. Icon: System.Drawing.Icon
    This property which inherited from System.Windows.Forms.Form specifies the icon to use on the top left corner of the balloon.

Here is some sample code that displays the BalloonHelp window.

BalloonHelp baloonHelp = new BalloonHelp();
		balloonHelp.ShowCloseButton = true;
		balloonHelp.Caption = "Sample Caption";
		balloonHelp.Content = "A multiline\r\ncontent";
		balloonHelp.CloseOnMouseClick = false;


There are lot of enchancements that could be done. I plan to add some of the following stuff:-

  1. BallonErrorProvider component - something similar to the standard ErrorProvider component in .NET.
  2. BalloonHelpProvider component -something similar to the standard HelpProvider component in .NET.
  3. There are ceratin optimzations that can be done to the rendering code.
  4. The balloon flickers a lot during resize in the designer. This needs to be fixed.

Finally, thanks to Joshua Heyer for his C++ code which laid the foundation for the code in this article.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Rama Krishna Vavilala
United States United States
No Biography provided

Comments and Discussions

GeneralRe: Notify Icon Pin
Domenic12-Aug-04 5:40
MemberDomenic12-Aug-04 5:40 
GeneralWould great if... Pin
Rocky Moore3-Aug-02 21:17
MemberRocky Moore3-Aug-02 21:17 
GeneralRe: Would great if... Pin
Nick Wong3-Aug-02 23:01
MemberNick Wong3-Aug-02 23:01 
GeneralRe: Would great if... Pin
Rocky Moore22-Oct-02 16:58
MemberRocky Moore22-Oct-02 16:58 
GeneralRe: Would great if... Pin
Zathrus19-Dec-02 0:37
MemberZathrus19-Dec-02 0:37 
GeneralAnd now to continue my jigging... Pin
Shog93-Aug-02 15:30
sitebuilderShog93-Aug-02 15:30 
GeneralRe: And now to continue my jigging... Pin
Rama Krishna Vavilala3-Aug-02 17:07
MemberRama Krishna Vavilala3-Aug-02 17:07 
GeneralNice :-) Pin
Shog93-Aug-02 17:19
sitebuilderShog93-Aug-02 17:19 
Rama Krishna wrote:
It is better to end the procrastanation soon.

Yes. You've got enough there now that anyone wishing to make use of it should be able to do what they want with at most minor modification. My take on it follows:

  • The form thing is very nice.
  • The object model is nice.
  • Not using bit flags to set options is sorta nice.
  • Margins seem too small.
  • The balloon can become too wide if no line breaks are entered in a large bit of text. Clamping at 1/2 or 2/3 of the screen width might be nice.
  • A move with parent option would be nice.
  • The article itself was clearly written and easily understandable.
  • The code looks nice. I'm not much of a C# person at present, but haven't had any problems reading it.

Keep up the good work! Smile | :)


If I could sleep forever, I could forget about everything...

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 2 Aug 2002


111 bookmarked