Notify tray Icon

S

shagshag

I know how to place a notify icon in the system tray and
how to hide the Form that owe the icon. The taskbar entry
button is hidden, ok, but I always get an entry for the
Form when I press "Alt+TAB". See my pb ?
 
B

Bret Mulvey

You probably don't even need the form at all. VS.NET automatically adds a
form to the project and adds Application.Run(new Form1()) to the static Main
method, but it's often totally unnecessary for a NotifyIcon application.
Example below. Note that it uses Application.Run() without a form parameter,
and the icon events can manipulate the Application state directly.

class MyApp
{
static NotifyIcon icon;

[STAThread]
static void Main()
{
icon = new NotifyIcon();
icon.Icon = new Icon("App.ico");
icon.Text = "Tooltip text here";
icon.Click += new EventHandler(Icon_Click);
icon.Visible = true;
Application.Run();
}

static void Icon_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Quit now?", "NotifyIcon",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
icon.Visible = false;
Application.Exit();
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top