8,734
社区成员
发帖
与我相关
我的任务
分享
iNotifyIcon = new System.Windows.Forms.NotifyIcon();
this.iNotifyIcon.Visible = false;
Stream st = NcResourceManager.Singleton.GetResource("/SiteDataManager.ico");
if (st != null)
{
try
{
this.iNotifyIcon.Icon = new System.Drawing.Icon(st);
System.Windows.Forms.MenuItem miExit = new System.Windows.Forms.MenuItem("退出", OnNotifyIconExitLick);
System.Windows.Forms.MenuItem miOpenWindow = new System.Windows.Forms.MenuItem("打开窗口", OnNotifyIconOpenWindow);
iNotifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu();
iNotifyIcon.ContextMenu.MenuItems.Add(miExit);
iNotifyIcon.ContextMenu.MenuItems.Add(miOpenWindow);
iNotifyIcon.DoubleClick += new EventHandler(OnNotifyIconOpenWindow);
iNotifyIcon.Text = this.Title + "--停止";
}
catch
{
iNotifyIcon = null;
}
}
protected override void OnStateChanged(EventArgs e)
{
base.OnStateChanged(e);
if (iNotifyIcon != null && this.WindowState == WindowState.Minimized)
{
this.iNotifyIcon.Visible = true;
this.ShowInTaskbar = false;
}
}
public void OnNotifyIconOpenWindow(object sender, EventArgs e)
{
this.iNotifyIcon.Visible = false;
this.ShowInTaskbar = true;
this.WindowState = WindowState.Normal;
this.Activate();
}
private void OnNotifyIconExitLick(object sender, EventArgs e)
{
this.Close();
}