Click here to Skip to main content
11,578,524 members (60,832 online)
Click here to Skip to main content

Balloon Windows for .NET

, 2 Aug 2002 CPOL 252.9K 6.7K 109
Rate this:
Please Sign up or sign in to vote.
A class that allows for balloon shaped forms in .NET
<!-- Download Links -->

Introduction

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).

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:-

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

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 AnchorPoint 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);
form.Show();		

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 AnchorPointFromControl 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;
		
balloonHelp.ShowBallon(textbox1);

Conclusion

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.

License

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

Share

About the Author

Rama Krishna Vavilala
Architect
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
Generalusing Rilling.Common.UI.Controls; Pin
Gary Huckabone8-Dec-09 8:09
memberGary Huckabone8-Dec-09 8:09 
The code references:
using Rilling.Common.UI.Controls;

Where do I find this?
AnswerRe: using Rilling.Common.UI.Controls; Pin
frknik22-Sep-10 22:55
memberfrknik22-Sep-10 22:55 
QuestionOpacity Problem Pin
ezi_ezi8-Aug-06 19:13
memberezi_ezi8-Aug-06 19:13 
AnswerRe: Opacity Problem Pin
lenowang16-Dec-09 16:00
memberlenowang16-Dec-09 16:00 
GeneralMemory leak bug Pin
yevgenyd25-Jun-06 3:29
memberyevgenyd25-Jun-06 3:29 
GeneralRe: Memory leak bug Pin
xCuenta26-Nov-07 10:01
memberxCuenta26-Nov-07 10:01 
GeneralRe: Memory leak bug Pin
Balder1978-23-May-08 21:39
memberBalder1978-23-May-08 21:39 
GeneralRe: Memory leak bug Pin
Rama Krishna Vavilala4-May-08 2:25
memberRama Krishna Vavilala4-May-08 2:25 
GeneralRe: Memory leak bug Pin
Balder1978-23-May-08 21:53
memberBalder1978-23-May-08 21:53 
GeneralRe: Memory leak bug Pin
Rama Krishna Vavilala4-May-08 2:23
memberRama Krishna Vavilala4-May-08 2:23 
GeneralAppearance question Pin
Bob-ish23-Aug-05 9:27
memberBob-ish23-Aug-05 9:27 
GeneralFound two bugs Pin
WillemM28-Jun-05 7:48
memberWillemM28-Jun-05 7:48 
GeneralRe: Found two bugs Pin
WillemM1-Sep-05 22:04
memberWillemM1-Sep-05 22:04 
GeneralRe: Found two bugs Pin
corsairX1-Nov-06 23:15
membercorsairX1-Nov-06 23:15 
Generalnot anchoring correctly Pin
MrBelvedr21-Feb-05 16:57
memberMrBelvedr21-Feb-05 16:57 
GeneralProgram hang Pin
Mark Focas8-Dec-03 18:08
memberMark Focas8-Dec-03 18:08 
GeneralFix for BalloonHelp not display in design mode Pin
Noosius227-Sep-03 13:45
memberNoosius227-Sep-03 13:45 
GeneralRe: Fix for BalloonHelp not display in design mode Pin
Nader Al Khatib4-Aug-07 9:26
memberNader Al Khatib4-Aug-07 9:26 
GeneralBalloon Window from System Tray Pin
SnoopyB20-Aug-03 10:55
sussSnoopyB20-Aug-03 10:55 
AnswerRe: Balloon Window from System Tray Pin
KaTu908-Dec-05 14:56
memberKaTu908-Dec-05 14:56 
GeneralLocking location to the control Pin
charliedurrant4-Jan-03 5:43
membercharliedurrant4-Jan-03 5:43 
GeneralRe: Locking location to the control Pin
kuerbis11-Aug-03 11:23
memberkuerbis11-Aug-03 11:23 
GeneralRe: Locking location to the control Pin
charliedurrant12-Aug-03 5:38
membercharliedurrant12-Aug-03 5:38 
GeneralRe: Locking location to the control Pin
lenowang16-Dec-09 15:41
memberlenowang16-Dec-09 15:41 
GeneralOperating Systems Supported Pin
David M. Kean15-Oct-02 18:00
memberDavid M. Kean15-Oct-02 18:00 
Generala small idea for consideration... Pin
Coz Kange3-Oct-02 19:52
memberCoz Kange3-Oct-02 19:52 
GeneralRe: a small idea for consideration... Pin
Chopper22-Oct-02 10:46
memberChopper22-Oct-02 10:46 
GeneralRe: a small idea for consideration... Pin
Peter Rilling7-Jan-03 1:22
memberPeter Rilling7-Jan-03 1:22 
GeneralRe: a small idea for consideration... Pin
Chopper23-Jan-03 7:41
memberChopper23-Jan-03 7:41 
GeneralRe: a small idea for consideration... Pin
eric vincent18-Apr-03 2:41
membereric vincent18-Apr-03 2:41 
GeneralRe: a small idea for consideration... Pin
Chopper18-Apr-03 3:21
memberChopper18-Apr-03 3:21 
GeneralRe: a small idea for consideration... Pin
WillemM29-Jun-03 6:01
memberWillemM29-Jun-03 6:01 
GeneralRe: a small idea for consideration... Pin
Peter Rilling8-Jan-03 21:56
memberPeter Rilling8-Jan-03 21:56 
GeneralRe: a small idea for consideration... Pin
Chopper18-Apr-03 3:31
memberChopper18-Apr-03 3:31 
QuestionIs there a simpler solution? Pin
Alastair Stell25-Aug-02 3:56
memberAlastair Stell25-Aug-02 3:56 
AnswerRe: Is there a simpler solution? Pin
Shog925-Aug-02 4:43
memberShog925-Aug-02 4:43 
AnswerRe: Is there a simpler solution? Pin
Rama Krishna9-Sep-02 4:31
memberRama Krishna9-Sep-02 4:31 
GeneralRe: Is there a simpler solution? Pin
Alastair G10-Sep-02 10:56
sussAlastair G10-Sep-02 10:56 
AnswerRe: Is there a simpler solution? Pin
corsairX1-Nov-06 23:39
membercorsairX1-Nov-06 23:39 
QuestionHow to force the balloon to one side? Pin
RFID Chris9-Aug-02 12:13
memberRFID Chris9-Aug-02 12:13 
AnswerRe: How to force the balloon to one side? Pin
Rama Krishna9-Aug-02 12:23
memberRama Krishna9-Aug-02 12:23 
GeneralNotify Icon Pin
rchecketts5-Aug-02 2:50
memberrchecketts5-Aug-02 2:50 
GeneralRe: Notify Icon Pin
Rama Krishna5-Aug-02 3:07
memberRama Krishna5-Aug-02 3:07 
GeneralRe: Notify Icon Pin
rchecketts5-Aug-02 5:12
memberrchecketts5-Aug-02 5:12 
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.w3-Aug-02 23:01
sussnick.w3-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
memberShog93-Aug-02 15:30 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150603.1 | Last Updated 3 Aug 2002
Article Copyright 2002 by Rama Krishna Vavilala
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid