您的位置:首页 > 编程语言 > C#

C#程序在托盘后台运行

2012-08-29 17:59 218 查看
源代码如下:

请在工具栏把notifyIcon控件拖入窗体再使用:

C#代码





//隐藏窗体

private bool windowCreate = true;

private void toolStripMenuItem1_Click(object sender, EventArgs e) //这是菜单选项的一个item点击事件

{

if (windowCreate)

{

base.Visible = false;

windowCreate = false;

}

this.Hide();

base.OnActivated(e);

}

//显示回窗体(notifyIcon控件双击事件,注:请选择一个ico图标,这样隐藏后在右下角显示有相关图标)

private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)

{

if (this.Visible == true)

{

this.Hide();

this.ShowInTaskbar = false;

}

else

{

this.Visible = true;

this.ShowInTaskbar = true;

this.WindowState = FormWindowState.Normal;

//this.Show();

this.BringToFront();

windowCreate = true;

}

}

若想直接打开程序后,自动后台运行的话,以下代码实现:

load函数中

this.Hide();

this.ShowInTaskbar = false;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: