10

How can I create a Popup balloon like you would see from Windows Messenger or AVG or Norton or whomever?

I want it to show the information, and then slide away after a few seconds.

Edit: It needs to be blocking like Form.ShowDialog() because the program exits after displaying the notification

divibisan
  • 11,659
  • 11
  • 40
  • 58
Malfist
  • 31,179
  • 61
  • 182
  • 269

3 Answers3

21

You can use the notifyIcon control that's part of .NET 2.0 System.Windows.Forms. That allows you to place an icon for your application in the System Tray. Then, you can call the ShowBalloonTip(int timeOut) method on that. Be sure however to first set the text, and icon properties on the notifyIcon for it to work. Small code sample:

private void button1_Click(object sender, EventArgs e)
        {
            this.notifyIcon1.BalloonTipText = "Whatever";
            this.notifyIcon1.BalloonTipTitle = "Title";
            this.notifyIcon1.Icon = new Icon("icon.ico");
            this.notifyIcon1.Visible = true;
            this.notifyIcon1.ShowBalloonTip(3);
        }

EDIT: Ok, so notifyIcon won't work for you. My second suggestion would then be to create your own control for this. Actually, I would use a form. A simple form, with no borders, and no control box and just have a timer running so you can set the Opacity for fade in/out. Then, you can easily get the bottom right of the screen using the Rectangle Screen.PrimaryScreen.WorkingArea. Then just show your form at that position.

BFree
  • 102,548
  • 21
  • 159
  • 201
11

Don't create a modal (blocking) balloon. Please. A big part of the design of these UIs is that they are not dialogs: they're transient, potentially non-interactive elements, intended to provide incidental information to a user without necessarily interrupting their workflow. A balloon that steals focus and blocks user input would be irritating at best - if you need a dialog, then use a dialog.

Shog9
  • 156,901
  • 35
  • 231
  • 235
  • The reason for the need for a blocking Notification Window is because the program exits after it's been displayed. If it is not blocking then it is never shown. – Malfist Jan 05 '09 at 17:31
  • Then at very least, please hide or destroy any other UI your program displays prior to displaying the balloon. In this way, you can avoid the perception of a blocking balloon by shielding the user from anything it might otherwise block. – Shog9 Jan 05 '09 at 17:39
  • The UI is not shown. The only time the balloon will appear is when the program has command line arguments. The command line argument will be a phone number from another application signaling the user has a call. If the phone number isn't in the database, that is when the balloon will be shown. – Malfist Jan 05 '09 at 19:06
  • Perhaps you would be better off leaving the UI up to your other program then. Pass back a return code indicating the error instead of blocking. There, now your program is both faster and more responsive. – Shog9 Jan 05 '09 at 19:31
  • I cannot touch the other program, it's closed source. – Malfist Jan 05 '09 at 19:38
1

The .NET 1.1 Visual Basic Power Pack had a toaster control.

jwmiller5
  • 2,584
  • 1
  • 15
  • 34