Windows Develop Bookmark and Share   
 index > Windows Forms General > Minimizing to system tray
 

Minimizing to system tray

I'm trying and failing at minimizing my program to my system tray. Can someone tell me what I'm doing wrong?

private void button3_Click(object sender, EventArgs e)
{
System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
ni.Icon = new System.Drawing.Icon("icon.ico");
ni.Visible = true;
ni.DoubleClick += delegate(object sender, EventArgs args)
{
this.Show();
this.WindowState = FormWindowState.Normal;
};

this.ShowInTaskbar = false;
}
  • Moved byHua Chen Friday, September 25, 2009 9:38 AMWindow Form Issue (From:Windows Presentation Foundation (WPF))
  •  
TheTrueFace  Friday, September 25, 2009 7:35 AM
Your method has a parameter named sender, and when you use sender name as a parameter at your delegate they confilict.

So change the name of the parameter at your anonymous delegate at NotifyIcon Doubleclick method tosomething else.

ni.DoubleClick +=

delegate(object sender1, EventArgs args)

  • Marked As Answer byTheTrueFace Sunday, September 27, 2009 7:36 PM
  • Proposed As Answer byTamer OzMVPSunday, September 27, 2009 4:27 PM
  •  
Tamer Oz  Sunday, September 27, 2009 9:28 AM
You are forgetting to call this.Hide().

Hans Passant.
nobugz  Friday, September 25, 2009 11:46 AM
Error 1 A local variable named 'sender' cannot be declared in this scope because it would give a different meaning to 'sender', which is already used in a 'parent or current' scope to denote something else ni.DoubleClick += delegate(object sender, EventArgs args)

that line errors, is my issue.
TheTrueFace  Sunday, September 27, 2009 9:09 AM
Your method has a parameter named sender, and when you use sender name as a parameter at your delegate they confilict.

So change the name of the parameter at your anonymous delegate at NotifyIcon Doubleclick method tosomething else.

ni.DoubleClick +=

delegate(object sender1, EventArgs args)

  • Marked As Answer byTheTrueFace Sunday, September 27, 2009 7:36 PM
  • Proposed As Answer byTamer OzMVPSunday, September 27, 2009 4:27 PM
  •  
Tamer Oz  Sunday, September 27, 2009 9:28 AM
Do you know how I would go about just loading the icon from the application's icon?
So I don't need to include the icon in the application build files.
TheTrueFace  Sunday, September 27, 2009 7:37 PM

You can use google to search for other answers

Custom Search

More Threads

• EditedFormatValue threw an exception
• Create movable text
• View options when using WebBrowser 2.0 component as directory browser.
• Determining Drive type at runtime
• How to scroll a listView Vertically and Horizontally?
• DataGridView Row Copying problem.
• Dictionary for using Date Comparison values
• Memory collects and doesn't let go...
• how to pass values to another windows application?
• can I use c# to explore 3D model made by VRML ? or any other better way?