建立一個(gè) contextMenu1 上面有4個(gè)菜單項(xiàng),miShowWindow,miShowIcon,miShowAll,miExit
然后設(shè)置主窗體和notifyIcon(此處實(shí)例是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);
}
}
}
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)
點(diǎn)擊舉報(bào)。