1. 拖一个notifyIcon和一个contextMenuStrip过来,他们会出现在窗体设计器的最下方:
然后完成你的menu,它暂时会出现在form上,但没关系,运行的时候不会显示。
2. 给notifyIcon设置icon属性,这一步很重要,不然系统托盘处不会有图标。然后将ContextMenuStrip属性设置为刚才的那个快捷菜单。
3. 现在运行程序的时候,任务栏右下角系统托盘处就会有我们的图标和菜单:
4. 现在我们来处理最小化隐藏和还原的问题:
首先要将form的ShowInTaskBar属性设为false,这样它就不会在任务栏中显示。但如果现在最小化,屏幕左下角仍然会有一条细小的标题栏。这里我们需要手工处理一下:
在form的resize事件里这样写:
private void frmMain_Resize(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { this.Visible = false; this.notifyIcon.Visible = true; } }
上面的代码会判断窗体的状态,如果是最小化的,则将窗体隐藏。
点击菜单中的“Open Main Window”还原窗体的代码:
private void openMainWindowToolStripMenuItem_Click(object sender, EventArgs e) { this.Visible = true; this.WindowState = FormWindowState.Normal; this.Show(); }
I want to remove only the title bar icon completely from my WPF application and it should work the same while sharing the screen,application icon,task bar icon,task bar preview window,switching to full screen and back to normal screen and vice versa. I have already tried with the existing solution present in stackexchange but none of them is durable and meeting the requirements,though it is very small requirement.