Hello everyone,

I was wondering how to get a program to run in the background without having it up and have an icon in the tray saying that it is running. I am guessing that it might be included with either system.windows.forms or System.Design or in Microsoft.Win32?
if anyone can help it would be great.
Thanks

Don't quote me on this, but it might have something to do with making it a service, rather than an application.

well, I want it to be able to come back to the top, like it is hiding in the tray waiting for the user to click on it and then it comes to the top.

Well Dark_Omen, your in luck i have been recently been working on the same thing myself for my program, only that i wanted the main program to go directly to tray when i minimised it and disapear from tray when i cliked on icon in tray. Anywho it works fine with me. Probably you might want to look into the background thing with a more experienced programmer, but here is what i've done.

First put a notify icon tool on the form you want to be in tray and program like so

in Windows Form designer put this code in the notifyicon section

this.notifyIcon1.Click += new System.EventHandler(this.notifyIcon1_Click);

then put in lines of code this:

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

then enter this code in Form_Load to prevent the form from showing and tay in tray

private void Form1_Load(object sender, System.EventArgs e)
		{
				this.Hide();
		notifyIcon1.Visible=true;
		}

but also make sure you have this in the Windows Form design in the Form area or just change properties to Window State to minimized

this.WindowState = System.Windows.Forms.FormWindowState.Minimized;

I hope this helps you out!
And write back if you cant get it to work
Happy coding!

Ok this is a little confusing for me, I am having trouble finding the places to put the code that you have posted. Do you think you could show me an example program using this.

Thanks

Sure! This is a program that will not work if compiled... Its just there to help you locate the areas where you should include the code.
I hope this helps you out! And concerning making the program run in the background, visit this site How To Create a Thread by Using Visual C# .NET

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace App
{
	public class Form1 : System.Windows.Forms.Form
	{
		private System.ComponentModel.IContainer components;;
		private System.Windows.Forms.NotifyIcon notifyIcon1;

		public Form1()
		{
			InitializeComponent();
			notifyIcon1.ContextMenu = this.contextMenu1;
			notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_Click);
		}
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#region Windows Form Designer generated code
		private void InitializeComponent() 
		{
                   this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
                   this.SuspendLayout();
			// 
			// notifyIcon1
			// 
			this.notifyIcon1.ContextMenu = this.contextMenu1;
			this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
			this.notifyIcon1.Text = "Something";
			this.notifyIcon1.Click += new System.EventHandler(this.notifyIcon1_Click);
                 }
		#endregion
		[STAThread]
		static void Main() 
		{
			System.Windows.Forms.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=false; //if you want to remove from tray when clicked on
		}
                private void Form1_Load(object sender, System.EventArgs e)
		{
				this.Hide();
		notifyIcon1.Visible=true;
		}

Ok I think I get it. Thanks for the help.

tell me if you hit any snags. I know it may seem confusing but its actually pretty simple. Anywho offer some feedback after trying to implement.

Cheerz!

I wan wondering if this code is the same when we programm in linux? Can you help me with this?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.