C#winform中怎么将程序最小化到系统托盘?

weixing06 2006-04-24 08:27:44
C#winform中怎么将程序最小化到系统托盘?
各位高手教教我!
...全文
293 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
txchen 2006-04-24
  • 打赏
  • 举报
回复
up
阿浩No_1 2006-04-24
  • 打赏
  • 举报
回复
收藏
happyhippy 2006-04-24
  • 打赏
  • 举报
回复
在form中添加一个NotifyIcon控件
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
notifyIcon1.Icon = new Icon("app.ico");//指定一个图标
notifyIcon1.Visible = false;
notifyIcon1.Click += new System.EventHandler(this.notifyIcon1_Click);
this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);

private void Form1_SizeChanged(object sender, EventArgs e)
{
if (this.WindowState==FormWindowState.Minimized)//最小化
{
his.ShowInTaskbar = false;
this.notifyIcon1.Visible=true;
}
}

private void notifyIcon1_Click(object Sender, EventArgs e)
//单击系统栏图标激活窗体
{
if (this.WindowState == FormWindowState.Minimized)
this.WindowState = FormWindowState.Normal;
this.Activate();
this.notifyIcon1.Visible = false;
this.ShowInTaskbar = true;
}
marvelstack 2006-04-24
  • 打赏
  • 举报
回复
首先需要在窗体中增加一个NotifyIcon控件,并给控件指定图片。

/// <summary>
/// 显示隐藏窗口
/// </summary>
/// <param name="showWindow"></param>
private void ShowHideWindow(bool showWindow)
{
if(showWindow == true)//显示
{
if(this.ShowInTaskbar==false)
{
this.ShowInTaskbar = true;
this.Visible = true;
//this.Show();
}
if(this.WindowState == FormWindowState.Minimized)
{
this.WindowState = FormWindowState.Normal;
}
this.Activate();
}
else//隐藏
{
if(this.WindowState == FormWindowState.Minimized)
{
this.WindowState = FormWindowState.Normal;
}
if(this.ShowInTaskbar == true)
{
this.ShowInTaskbar = false;
this.Visible = false;
//this.Hide();

}
}
}

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧