views:

564

answers:

3

How can I have my application minimize itself to the system tray in WindowsXP/Vista?

I'm also looking for a way to have a message display itself when the mouse is hovered on the icon. Is it possible to have two lines in the pop up balloon?

+4  A: 

try

to minimize

this.WindowState = FormWindowState.Minimized;

to minimize to tray see this

http://stackoverflow.com/questions/46918/whats-the-proper-way-to-minimize-to-tray-a-c-winforms-app

Bye

RRUZ
This only minimizes it to the lower bar. I want it to become a little icon next to the clock, can you help? :P
Sergio Tapia
@Papuccino1: you mean you want it to appear in the system tray.
MusiGenesis
Yeah, I got mixed up in terms. :D Care to help?
Sergio Tapia
I updated my answer. You need to use a NotifyIcon control.
MusiGenesis
A: 

The popup balloon will display whatever is shown in the form's title bar (which is the form's .Text property). I don't know of any way to make it multi-lined (if there is a way, it's sure to be complicated and probably not worth the trouble).

This earlier question gives some answers to the basic question. Your toolbox contains a control called NotifyIcon - use this to place an icon in the system tray.

MusiGenesis
+5  A: 

I assume you mean minimize to the System tray because you have talked about icons and message ballons?

The following code will set up a tray icon:

private void SetUpTrayIcon()
{
    notifyIcon = new System.Windows.Forms.NotifyIcon();
    notifyIcon.BalloonTipText = "Ballon minimize text";
    notifyIcon.BalloonTipTitle = "Ballon minimize title";
    notifyIcon.Text = "Icon hover text";
    notifyIcon.Icon = new  System.Drawing.Icon(
               System.Reflection.Assembly.GetExecutingAssembly()
                   .GetManifestResourceStream("MyIcon.ico"));
    notifyIcon.Click += new EventHandler(HandlerToMaximiseOnClick);
}

To show the icon in the tray (you may want to do this on the window state change event for example, do something like the following:

if (notifyIcon != null)
{
    notifyIcon.Visible = true;
    notifyIcon.ShowBalloonTip(2000);
}

To display a ballon on mouse hover you want to use the same code as above possibly in the mousemove for the icon.

Note: ShowBalloonTip is overloaded if you want to change the message at different points. The message the balloon displays will respect newlines eg Environment.NewLine can be added to it.

Simon Fox
Thanks bro, I'll try this out! :)
Sergio Tapia