建立一個 contextMenu1 上面有4個菜單項,miShowWindow,miShowIcon,miShowAll,miExit
然后設(shè)置主窗體和notifyIcon(此處實例是ni)的contextMenu為此contextMenu1,單擊菜單可以看到效果,如果最小化也要推到托盤的話,可能要用到其它事件 ................................................................. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Notify
{ public partial class Notify : Form { public Notify() { InitializeComponent(); } private void miShowWindow_Click(object sender, EventArgs e)
{ //顯示窗體 this.Visible = true; this.ni.Visible = false; } private void miShowAll_Click(object sender, EventArgs e)
{ //顯示全部 this.Visible = true; this.ni.Visible = true; } private void miShowIcon_Click(object sender, EventArgs e)
{ //顯示托盤 this.Visible = false; this.ni.Visible = true; } private void miExit_Click(object sender, EventArgs e)
{ Application.Exit(); } private void ni_Click(object sender, EventArgs e)
{ //顯示托盤 miShowWindow_Click(sender, e); } } } |
|