954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C#,system tray, wont go from task bar.

hello people :)

found this site via google and its helped me a great deal so far but ive hit a snag.

from this topic:
http://www.daniweb.com/techtalkforums/thread19672.html

ive managed to create an app that will sit in the system tray and can be minimised and restroed again but the problem is it wont disepear from the task bar. being a complete begginner at this stuff i have no idea where to look.

i was wondering if anyone can help me heres my code:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication2
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.NotifyIcon notifyIcon1;
		private System.ComponentModel.IContainer components;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_Click);
			this.SuspendLayout();
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
			// 
			// notifyIcon1
			// 
			this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
			this.notifyIcon1.Text = "notifyIcon1";
			this.notifyIcon1.Visible = true;
			this.notifyIcon1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseDown);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 266);
			this.Name = "Form1";
			this.Text = "Form1";
			this.Load += new System.EventHandler(this.Form1_Load);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void notifyIcon1_Click(object sender, EventArgs e)
		{
			if (this.WindowState == FormWindowState.Minimized)
				this.Show();
			this.WindowState = FormWindowState.Normal;
			this.Activate();
			notifyIcon1.Visible=true; //if you want to remove from tray when clicked on
		}
		private void Form1_Load(object sender, System.EventArgs e)
		{
			this.Hide();
			notifyIcon1.Visible=true;
		}

		private void notifyIcon1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
		
		}
	}
}

i added this to the onload procedure, great it works but it just moves the app so its floating above the start menu which is no good to me

this.ShowInTaskbar = false;

anyone have any idea idea what could be up
im sure its pretty simple but i cant see it

many thanks
adam

tenbellys
Newbie Poster
1 post since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

You have to set the Visible property to false, or call the this.Hide() method.

Iron_Cross
Junior Poster
117 posts since Jul 2003
Reputation Points: 46
Solved Threads: 2
 

Try this site
under small problem, you may need to use dispose, not sure
http://www.codeproject.com/csharp/trayiconmenu01.asp

ilovcars
Newbie Poster
1 post since Jun 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You