Sorry, this is not complete, for example it does not show me what is going
on in InitializeComponent(), and does not show me what you are doing with
micoPending, micoRunning & micoStopped. The example also does not show me
how you are responding to either the Click or DoubleClick events of the
NotifyIcon object. For that matter it doesn't show that you even have a
TrayIcon object.
With all that said, if I add your code to mine the window minimizes and
hides with the tray icon still visible. So I'm sorry to say it still works
for me here.
Paste the following code as your form make sure you assign an icon to the
NotifyIcon object, then tell me if this works for you.
Regards
Brian W
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();
// 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.DoubleClick += new
System.EventHandler(this.notifyIcon1_DoubleClick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_SizeChanged(object sender, System.EventArgs e)
{
if ( this.WindowState == FormWindowState.Minimized )
this.Hide();
else
this.Show();
}
private void notifyIcon1_DoubleClick(object sender, System.EventArgs e)
{
this.Show();
}
}
Zeljko said:
Sure - here it is:
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//PENDING_ICON etc are string constants - I added 3 icons to
the app, changing current notify icon based on the status of a windows
service
micoPending = new Icon(typeof(Form1), PENDING_ICON);
micoRunning = new Icon (typeof (Form1) , RUNNING_ICON);
micoStopped = new Icon (typeof (Form1) , STOPPED_ICON);
}
protected override void OnLayout(LayoutEventArgs levent)
{
switch (WindowState){
case FormWindowState.Minimized:
this.WindowState = FormWindowState.Minimized;
this.Hide();
break;
case FormWindowState.Maximized:
this.WindowState = FormWindowState.Normal;
this.Show();
this.Activate();
break;
}
base.OnLayout (levent);
}