14

I have been working with NotifyIcon in order to show an icon in the taskbar. This program has no Windows Form. I perhaps could create one and make it invisible but I was hoping to avoid it. The ToolTip functions attached to NotifyIcon are somewhat lacking, and one of the gurus here suggested I look at the ToolTip functionality. It is possible to attach ToolTip to a form. Is is possible to attach it to just the NotifyIcon? I'm trying do this:

NotifyIcon CTicon = new NotifyIcon();
ToolTip toolTip = new ToolTip();
toolTip.SetToolTip(CTicon, "Test");

And I get the error "cannot convert from 'System.Windows.Forms.NotifyIcon' to 'System.Windows.Forms.Control'. Is there a way to convert? I also tried:

toolTip.SetToolTip(CTicon.Container, "Test");

but a container is apparently not a valid control either. I apologize for my total lack of understanding of how this may or may not work.

Thanks in advance.

Greycrow
  • 1,493
  • 5
  • 18
  • 29
  • 2
    NotifyIcons and system tray seem to be on there way out in Windows 7, tool bar preview with buttons and menus are on there way in instead. You might want to take this into consideration for new software. – Danny Varod Mar 25 '11 at 23:46

6 Answers6

33

A belated answer, but maybe useful for others .

NotifyIcon.Text = "ToolTipText";
prabhakaran
  • 4,706
  • 13
  • 63
  • 103
3

Tray icons don't support square tool tips, only balloons. Kinda makes sense, the icons are usually quite close together so it would be hard to see what icon produced the tip without the "stem" on the balloon. Use the NotifyIcon.BalloonTipText property.

Hans Passant
  • 873,011
  • 131
  • 1,552
  • 2,371
1

All the tray icons on my computer have tooltips. You need to create your NotifyIcon using the constructor that accepts a Component as an argument. It displays the NotifyIcon.Text property.

I was able to create one using the example code here: http://msdn.microsoft.com/en-us/library/1by05f8d.aspx

using System;
using System.Drawing;
using System.Windows.Forms;

public class Form1 : System.Windows.Forms.Form
{
    private System.Windows.Forms.NotifyIcon notifyIcon1;
    private System.Windows.Forms.ContextMenu contextMenu1;
    private System.Windows.Forms.MenuItem menuItem1;
    private System.ComponentModel.IContainer components;

    [STAThread]
    static void Main() 
    {
        Application.Run(new Form1());
    }

    public Form1()
    {
        this.components = new System.ComponentModel.Container();
        this.contextMenu1 = new System.Windows.Forms.ContextMenu();
        this.menuItem1 = new System.Windows.Forms.MenuItem();

        // Initialize contextMenu1 
        this.contextMenu1.MenuItems.AddRange(
                    new System.Windows.Forms.MenuItem[] {this.menuItem1});

        // Initialize menuItem1 
        this.menuItem1.Index = 0;
        this.menuItem1.Text = "E&xit";
        this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);

        // Set up how the form should be displayed. 
        this.ClientSize = new System.Drawing.Size(292, 266);
        this.Text = "Notify Icon Example";

        // Create the NotifyIcon. 
        this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);

        // The Icon property sets the icon that will appear 
        // in the systray for this application.
        notifyIcon1.Icon = new Icon("appicon.ico");

        // The ContextMenu property sets the menu that will 
        // appear when the systray icon is right clicked.
        notifyIcon1.ContextMenu = this.contextMenu1;

        // The Text property sets the text that will be displayed, 
        // in a tooltip, when the mouse hovers over the systray icon.
        notifyIcon1.Text = "Form1 (NotifyIcon example)";
        notifyIcon1.Visible = true;

        // Handle the DoubleClick event to activate the form.
        notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);

    }

    protected override void Dispose( bool disposing )
    {
        // Clean up any components being used. 
        if( disposing )
            if (components != null)
                components.Dispose();            

        base.Dispose( disposing );
    }

    private void notifyIcon1_DoubleClick(object Sender, EventArgs e) 
    {
        // Show the form when the user double clicks on the notify icon. 

        // Set the WindowState to normal if the form is minimized. 
        if (this.WindowState == FormWindowState.Minimized)
            this.WindowState = FormWindowState.Normal;

        // Activate the form. 
        this.Activate();
    }

    private void menuItem1_Click(object Sender, EventArgs e) {
        // Close the form, which closes the application. 
        this.Close();
    }
}
bwest
  • 8,098
  • 3
  • 23
  • 54
1

NotifyIcon is used for the system tray icon that you see on the bottom right hand corner of the screen, usage of ToolTip is only for controls such as textboxes, checkboxes and so on...for example, let's assume there's a TextBox instance called 'textBox1', on the form than this would work:

toolTip1.SetToolTip(textBox1, "Hello World");

Now, when you mouse-over the textbox, a tooltip is shown...

t0mm13b
  • 32,846
  • 7
  • 71
  • 106
1

I'm not sure you can set a tooltip directly on a notify icon. It's the same thing as setting the text property on the notify icon itself. There are some limitations to the notify icon text. It's limited to 128 chars and will only stay up for a short amount of time. If you want to display more info for a longer amount of time you should look at the balloon text property of the notify icon. I highly suggest reading the MSDN page it's quite helpful.

http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.aspx

Justin
  • 3,726
  • 1
  • 17
  • 20
  • *Note: According to the documentation for Text under the link you provided above, the limit for Text is 63 characters (see the Exceptions section): http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.text.aspx – Josh Stribling Feb 24 '12 at 00:59
1

You shouldn't.

NotifyIcon is used to show notifications, whereas ToolTip is used to show the information about the user's current activity, it should be used "in place".

Check the user interface guidelines:

  1. Notifications
  2. Balloons
AZ.
  • 6,663
  • 6
  • 38
  • 61
  • 2
    That's the theory. The practice of the past decade or so has been that notify icons aren't actually used for notifications at all, but rather for low-profile UIs. – Roman Starkov May 29 '11 at 23:06