Winform最小化到托盘
程序员文章站
2022-03-31 19:09:18
...
1.先将Notifyicon控件拖入主窗体中
2.设置Text和icon属性
3.设置双击托盘图标后的方法
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
//还原窗体显示
WindowState = FormWindowState.Normal;
//**窗体并给予它焦点
this.Activate();
//任务栏区显示图标
this.ShowInTaskbar = true;
//托盘区图标隐藏
notifyIcon1.Visible = false;
}
}
4.设置程序最小化后显示托盘
private void Form1_SizeChanged(object sender, EventArgs e)
{
//判断是否选择的是最小化按钮
if (WindowState == FormWindowState.Minimized)
{
//隐藏任务栏区图标
this.ShowInTaskbar = false;
//图标显示在托盘区
notifyIcon1.Visible = true;
}
}
上一篇: VS最小化程序到托盘