1.设置WinForm窗体属性showinTask=false

2.加notifyicon控件notifyIcon1,为控件notifyIcon1的属性Icon添加一个icon图标。

3.添加窗体最小化事件(首先需要添加事件引用):

this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);

private void Form1_SizeChanged(object sender, EventArgs e) 

if(this.WindowState == FormWindowState.Minimized) 

this.Hide(); 
this.notifyIcon1.Visible=true; 

}

4.添加点击图标事件(首先需要添加事件引用):

private void notifyIcon1_Click(object sender, EventArgs e) 

this.Visible = true; 
this.WindowState = FormWindowState.Normal; 
this.notifyIcon1.Visible = false; 
}

5.可以给notifyIcon添加右键菜单:

主窗体中拖入一个ContextMenu控件NicontextMenu,点中控件,在上下文菜单中添加菜单,notifyIcon1的ContextMenu行为中选中NicontextMenu 作为上下文菜单。

this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); 
this.NicontextMenu = new System.Windows.Forms.ContextMenu(); 
this.menuItem_Hide = new System.Windows.Forms.MenuItem(); 
this.menuItem_Show = new System.Windows.Forms.MenuItem(); 
this.menuItem_Aubot = new System.Windows.Forms.MenuItem(); 
this.menuItem_Exit = new System.Windows.Forms.MenuItem();

this.notifyIcon1.ContextMenu = this.NicontextMenu; 
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject( "NotifyIcon.Icon "))); 
this.notifyIcon1.Text = " "; 
this.notifyIcon1.Visible = true; 
this.notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick); 
this.notifyIcon1.Click += new System.EventHandler(this.notifyIcon1_Click);

this.NicontextMenu.MenuItems.AddRange(

new System.Windows.Forms.MenuItem[] 

this.menuItem_Hide, 
this.menuItem_Show, 
this.menuItem_Aubot, 
this.menuItem_Exit 

);

// 
// menuItem_Hide 
// 
this.menuItem_Hide.Index = 0; 
this.menuItem_Hide.Text = "隐藏 "; 
this.menuItem_Hide.Click += new System.EventHandler(this.menuItem_Hide_Click); 
// 
// menuItem_Show 
// 
this.menuItem_Show.Index = 1; 
this.menuItem_Show.Text = "显示 "; 
this.menuItem_Show.Click += new System.EventHandler(this.menuItem_Show_Click); 
// 
// menuItem_Aubot 
// 
this.menuItem_Aubot.Index = 2; 
this.menuItem_Aubot.Text = "关于 "; 
this.menuItem_Aubot.Click += new System.EventHandler(this.menuItem_Aubot_Click); 
// 
// menuItem_Exit 
// 
this.menuItem_Exit.Index = 3; 
this.menuItem_Exit.Text = "退出 "; 
this.menuItem_Exit.Click += new System.EventHandler(this.menuItem_Exit_Click);

protected override void OnClosing(CancelEventArgs e) 

this.ShowInTaskbar = false; 
this.WindowState = FormWindowState.Minimized; 
e.Cancel = true; 

protected override void OnClosing(CancelEventArgs e) 

//this.ShowInTaskbar = false; 
this.WindowState = FormWindowState.Minimized; 
e.Cancel = true; 
}

private void CloseCtiServer() 

timer.Enabled = false; 
DJ160API.DisableCard(); 
this.NotifyIcon.Visible = false; 
this.Close(); 
this.Dispose(); 
Application.Exit(); 
}

private void HideCtiServer() 

this.Hide(); 
}

private void ShowCtiServer() 

this.Show(); 
this.WindowState = FormWindowState.Normal; 
this.Activate();


private void CtiManiForm_Closing(object sender, System.ComponentModel.CancelEventArgs e) 

this.CloseCtiServer(); 
}

private void menuItem_Show_Click(object sender, System.EventArgs e) 

this.ShowCtiServer(); 
}

private void menuItem_Aubot_Click(object sender, System.EventArgs e) 
{

}

private void menuItem_Exit_Click(object sender, System.EventArgs e) 

this.CloseCtiServer(); 
}

private void menuItem_Hide_Click(object sender, System.EventArgs e) 

this.HideCtiServer(); 
}

private void CtiManiForm_SizeChanged(object sender, System.EventArgs e) 

if(this.WindowState == FormWindowState.Minimized) 

this.HideCtiServer(); 

}

private void notifyIcon1_DoubleClick(object sender,System.EventArgs e) 

this.ShowCtiServer(); 
}

C#编写最小化时隐藏为任务栏图标的 Window appllication.的更多相关文章

  1. C# 编写最小化时隐藏为任务栏图标的Window appllication

    1.设置窗体属性showinTask=false 2.加notifyicon控件notifyIcon1,为控件notifyIcon1的属性Icon添加一个icon图标. 3.添加窗体最小化事件(首先需 ...

  2. Mac的最小化和隐藏的区别

    Mac 中应用程序窗口的最小化和隐藏的快捷键: CMD + H 隐藏应用程序 CMD + M 最小化应用程序 重点在于两点的区别: 最小化会隐藏当前应用程序的窗口,不切换当前的应用程序:隐藏应用程序会 ...

  3. Windows 窗体最小化和隐藏的区别及恢复

    应用程序有托盘图标,窗体最小化或者隐藏窗体时,点击托盘图标需要恢复窗体显示,并且恢复之前的现实状体,正常大小或者最大化显示.例如:最大化显示窗体时,点击最小化按钮,窗体最小化,点击托盘图标将最大化显示 ...

  4. QT:窗口最小化时显示一个小浮标

    有些窗口在自身最小化时要在桌面上显示一个小浮标,让用户利用这个小浮标进行各种操作(例如迅雷的悬浮窗一样),我试着用QT实现一下这个功能. PS:本来以为这个功能很简单,却搞了我两个晚上,泪奔... 思 ...

  5. delphi模态窗体最小化会隐藏的问题

    在使用delphi创建模态窗体的时候最小化窗体会导致最小化的窗体不可见,再次点击主窗体才会显示. 在这个模态窗体中增加以下函数 procedure WmSysCommand(var msg: TMes ...

  6. winform最小化后隐藏到右下角,单击或双击后恢复 .

    01.//先拖一个notifyIcon控件进来 02. 03.//然后在您的notifyIcon控件中添加 MouseDoubleClick事件,代码如下 04. 05. private void n ...

  7. 线性回归(Linear Regression)均方误差损失函数最小化时关于参数theta的解析解的推导(手写)

    第一页纸定义了损失函数的样子, theta, X 和 y 的 shape, 以及最终的损失函数向量表现形式. 第二页纸抄上了几个要用到的矩阵求导公式,以及推导过程和结果. 要说明的是:推导结果与the ...

  8. UIScrollView滚动时隐藏底部导航栏问题

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView { NSLog(@"開始滚动"); int currentPostio ...

  9. delphi如何让程序最小化到任务栏(转)

    现在很多的应用程序都有这样一种功能,当用户选择最小化窗口时,窗口不是象平常那样最小化到任务栏上,而是“最小化”成一个任务栏图标.象FoxMail 3.0 NetVampire 3.0等都提供了这样的功 ...

随机推荐

  1. C# Color

    一.创建一个Color对象: Color c=Color.FromKnownColor(KnownColor.colorname); 二.四种同样颜色的不同方式: Color c1=Color.Fro ...

  2. 使用PowerShell向SharePoint中写入数据

    本文介绍了如何在命令行方式下, 创建自定义列表, 将外部数据导入到列表以及生成视图. $listname = "contact0422" $column_text = @( &qu ...

  3. 将/home目录从单独的分区迁移回/目录下

    安装系统的时候, 将/, swap, /home这三个目录放在了三个不同的分区, 现在希望将/home目录移回/目录下. 1. umount /home, 然后在/目录下创建/home_new, 通过 ...

  4. my first go

    package main import "fmt" func main() { var num1 int =5 for num1>0 { fmt.Println(" ...

  5. 《Linux内核分析》第一周 计算机是如何工作的?

    刘蔚然 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000] WEEK ONE(2. ...

  6. windows7打印时,显示脱机,提示“服务器打印后台处理程序服务没有运行”。

    1. 问题 windows7打印时,显示脱机,提示“服务器打印后台处理程序服务没有运行”. 2. 解决方法. 将下面的文字保存为bat文件执行,其中\\192.168.40.110\Lenovo M7 ...

  7. JAVA Math类

    public class MathTest{ public static void main(String[] args)  {  /*---------下面是三角运算---------*/  //将 ...

  8. MVC中的视图

    视图的作用: 检查由路由器提交的模型对象, 将其内容转换为HTML格式. 指定视图的两种方式, 代码如下: return View("NotIndex"); return View ...

  9. cxf client在后台不通且chunk设置为false的时候不能在控制台输出请求日志

    场景: 服务编排框架支持编排webservice服务.call webservice的client是基于cxf做的.为了使用服务编排的开发者调试与定位问题方便,需要将webservice的请求与响应报 ...

  10. 简要介绍Apache、php、mysql安装和工具介绍

    1 安装Apache 网站:www.Apache.org下载相应的Apache,目前下载了近期的:httpd-2.2.15-win32-x86-openssl-0.9.8msi 安装简要步骤如下图: ...