您的位置:资讯频道 > 技术文档 > 其 它

使用NotifyIcon控件创建任务栏托盘

来源:博客   作者:不详   时间:2008-04-24  点击:404 次
namespace NotifyIcon
...{
 public partial class Form1 : Form
 ...{
  public Form1()
  ...{
   InitializeComponent();
  }

  private void Form1_Load(object sender, EventArgs e)
   ...{
    this.components = new Container();
   System.Windows.Forms.NotifyIcon notifyicon = new System.Windows.Forms.NotifyIcon(this .components );
   notifyicon.Text = "演示创建托盘";
   notifyicon.Visible = true;
   ResourceManager resourceManager = new ResourceManager("NotifyIcon.Properties.Resources", GetType().Module.Assembly);//从资源文件中添加图标
   notifyicon.Icon = resourceManager.GetObject("icon1") as Icon;
    MenuItem menuitem = new MenuItem("退出程序");
   notifyicon.ContextMenu = new ContextMenu(new MenuItem[] ...{ menuitem });
   menuitem.Click += new EventHandler(menuitem_Click);
   notifyicon.MouseClick += new MouseEventHandler(notifyicon_MouseClick);

  }

  void notifyicon_MouseClick(object sender, MouseEventArgs e)
  ...{
   //throw new Exception("The method or operation is not implemented.");
    if (this.WindowState == FormWindowState.Minimized)
     this.WindowState = FormWindowState.Normal;
  }

  void menuitem_Click(object sender, EventArgs e)
  ...{
   //throw new Exception("The method or operation is not implemented.");
   Application.Exit();
  }
 }
}