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. UFS

    ● UFS vs eMMC 1. UFS有分离的读写通道,可以同时进行读写操作(双向),但是eMMC在同一时刻只能读或写. 2. UFS有一个命令队列,将命令进行排序.因此,多个命令可以同时处理,从而 ...

  2. 1CSS与文档

    层叠样式表(Cascading Style Sheet,CSS)的功能十分强大,可以影响一个或一组文档的表现. 为什么结构化对HTML来说很重要:1.非结构化页面使得建立内容索引极为困难.2.缺乏结构 ...

  3. CentOS7配置日志(VirtualBox)

    版本为CentOS-Minimal 1.VirtualBox下安装CentOS. 新建虚拟机 下载CentOS,放入盘片,启动虚拟机,按提示开始安装(建议内存1G,硬盘10G以上)   2. 设置网络 ...

  4. JAVA程序改错 (易错题)

    JAVA程序改错 1. abstract class Name { private String name; public abstract boolean isStupidName(String n ...

  5. iOS:给Git仓库上传代码时,超过100M会被拒绝(例如github和oschina)

    处理GitHub不允许上传大于100M文件问题?本人也遇到这个坑... 来自转载,原文链接:http://www.cnblogs.com/qmmq/p/4604862.html 1.报错: 自己的项目 ...

  6. MyBatis(2):config.xml文件

    前言 前一篇文章,讲了MyBatis入门,讲到了MyBatis有两个基本的配置文件,一个用来配置环境信息,一个用来写SQL语句.前者我把它命名为config.xml,config.xml的内容是: 1 ...

  7. AndroidStudio第一个项目HelloWorld

    实验内容 在Android Studio中创建项目 创建并启动Android模拟器 项目的编译和运行 实验要求 在安装好的AndroidStudio上建立第一个工程 创建并启动Android模拟器 编 ...

  8. Java回顾之Spring基础

    第一篇:Java回顾之I/O 第二篇:Java回顾之网络通信 第三篇:Java回顾之多线程 第四篇:Java回顾之多线程同步 第五篇:Java回顾之集合 第六篇:Java回顾之序列化 第七篇:Java ...

  9. phpstorm-----------如何激活phpstorm2016

    新版激活方法: 1.在线激活 菜单help >>>> Register 选择License Server 输入 http://idea.qinxi1992.cn/ 点击ok 2 ...

  10. 11. 星际争霸之php设计模式--备忘模式

    题记==============================================================================本php设计模式专辑来源于博客(jymo ...