Description : Creating Tray icon is very simple in .net. By using the following code we can creat the Tray Icon for our Projects.
Namespace part
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data;
Coding part
namespace WindowsApplication1 { public partial class Form1 : Form { private System.Windows.Forms.NotifyIcon MyNotifyIcon; private System.Windows.Forms.ContextMenu MyContextMenu; private System.Windows.Forms.MenuItem MyMenuItem1; private System.Windows.Forms.MenuItem MyMenuItem2; private System.Windows.Forms.MenuItem MyMenuItem3;
public Form1() { InitializeComponent(); } private void InitializeComponent() { this.MyNotifyIcon = new NotifyIcon(new System.ComponentModel.Container()); this.MyContextMenu = new System.Windows.Forms.ContextMenu(); this.MyMenuItem1 = new System.Windows.Forms.MenuItem(); this.MyMenuItem2 = new System.Windows.Forms.MenuItem(); this.MyMenuItem3 = new System.Windows.Forms.MenuItem(); this.SuspendLayout();
this.MyNotifyIcon.ContextMenu = this.MyContextMenu; this.MyNotifyIcon.Icon = new System.Drawing.Icon("MyIcon.ico"); this.MyNotifyIcon.Text = "My Tray Icon"; this.MyNotifyIcon.Visible = true; this.MyContextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.MyMenuItem1, this.MyMenuItem2, this.MyMenuItem3}); this.MyMenuItem1.Index = 0; this.MyMenuItem1.Text = "Exit"; this.MyMenuItem1.Click += new System.EventHandler(this.menuItem1_Click); this.MyMenuItem2.Index = 1; this.MyMenuItem2.Text = "Hide"; this.MyMenuItem2.Click += new System.EventHandler(this.menuItem2_Click); this.MyMenuItem3.Index = 2; this.MyMenuItem3.Text = "Show"; this.MyMenuItem3.Click += new System.EventHandler(this.menuItem3_Click); this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(504, 365); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); }
private void menuItem1_Click(object sender, System.EventArgs e) { Close(); }
private void menuItem2_Click(object sender, System.EventArgs e) { this.Visible = false; }
private void menuItem3_Click(object sender, System.EventArgs e) { this.Visible = true; }
private void Form1_Load(object sender, EventArgs e) {
} } }
By Nathan
|
No responses found. Be the first to respond and make money from revenue sharing program.
|