Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having the application minimize to the system tray when button is clicked?

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?

like image 431
Sergio Tapia Avatar asked Aug 18 '09 23:08

Sergio Tapia


People also ask

How do I minimize apps to system tray?

Press Alt + F1 and that window will minimize to the tray.

What does it mean to minimize to system tray?

To interact with a program in the system tray, select an icon with the mouse and double-click or right-click the icon. When minimizing the program after using it, it shrinks back into the system tray instead of into the main part of the taskbar.

How do I move apps to my system tray?

Select Start , scroll to the app you want to pin, then press and hold (or right-click) the app. Select More > Pin to taskbar. If the app is already open on the desktop, press and hold (or right click) the app's taskbar icon, and then select Pin to taskbar.


2 Answers

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.

like image 137
Simon Fox Avatar answered Oct 02 '22 05:10

Simon Fox


try

to minimize

this.WindowState = FormWindowState.Minimized;

to minimize to tray see this

What's the proper way to minimize to tray a C# WinForms app?

Bye

like image 27
RRUZ Avatar answered Oct 02 '22 05:10

RRUZ