
icon in the taskbar notification area(where we see the system time) (Urgent Help)
Hi,
In order to make the icon appear on tray area, try the following code:
private bool bCanClose;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.bCanClose = false;
//
// 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);
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
//
// notifyIcon1
//
this.notifyIcon1.ContextMenu = this.contextMenu1;
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
this.notifyIcon1.Text = "notifyIcon1";
this.notifyIcon1.Visible = true;
//
// contextMenu1
//
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem2});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.Text = "Close Me";
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.Text = "Show Me";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Name = "Form1";
this.Text = "Form1";
this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
this.GiveFeedback += new System.Windows.Forms.GiveFeedbackEventHandler(this.Form1_GiveFeedback);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
MessageBox.Show(this, "Changed!");
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (!this.bCanClose)
{
e.Cancel = true;
this.Hide();
}
}
private void Form1_GiveFeedback(object sender, System.Windows.Forms.GiveFeedbackEventArgs e)
{
}
private void menuItem1_Click(object sender, System.EventArgs e)
{
this.bCanClose = true;
this.Close();
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
this.Show();
}
Best regards,
Richard Chen
Microsoft
This posting is provided "AS IS" with no warranties, and confers no rights.