直接附上代码:
先将notifyIcon,contextMenuStrip控件拖到新建的窗体中,然后设置窗体的事件:
private void Index_SizeChanged(object sender, EventArgs e)
{
if (this.WindowState ==FormWindowState.Minimized )
{
this.Hide();
this.notifyIcon1.Visible = true;
}
然后再设置notifyIcon的点击事件:
private void notifyIcon1_Click(object sender, EventArgs e)
{
this.Visible = true;
this.WindowState = FormWindowState.Normal;
}
PS:要在属性加上一个图标,不然任务栏里面右下角看不到你的图标的,默认是无的。
一个托盘功能的程序就写完了!