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. JavaScript 入门教程二 在HTML中使用 JavaScript

    一.使用 <script> 元素的方式有两种:直接在页面中嵌入 JavaScript 代码和引用外部 JavaScript 文件. 二.使用内嵌方式,一般写法为: <script t ...

  2. yield return的用法简介

    使用yield return 语句可一次返回一个元素. 迭代器的声明必须满足以下要求: 返回类型必须为 IEnumerable.IEnumerable<T>.IEnumerator 或 I ...

  3. MyEclipse 8.5整合Git,并在Github上发布项目【转】

    最近Git火得如日中天,而且速度体验和团队模式都很不错.手头正好有个学生实训项目,时间紧任务重,而且学校内网管理太紧,所以就想借助于Internet的分布式开发,因此想到了Github. 经过一天的调 ...

  4. 关于js SDK的程序,java SDK的程序

    一:JS SDK 1.修改配置workspace 2.导入 3.Demo.html <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Trans ...

  5. CAShapeLayer(持续更新)

    CAShapeLayer 之前讲过CALayer动画相关知识,再来看看更加复杂的CAShapeLayer相关的动画知识. 普通CALayer在被初始化时是需要给一个frame值的,这个frame值一般 ...

  6. 去掉comments

    三种comments: /* Test program */ int main() { // variable declaration int a, b, c; /* This is a test m ...

  7. Matlab代码备忘

    1.Matlab写入文件  set(hp1,'xdata',bbb(1,:),'ydata',bbb(2,:),'zdata',bbb(3,:)); M=size(bbb,2); name=strca ...

  8. @Autowired获取被@Service注解的bean为null的问题

    先说结论:Spring容器还没有加载完Bean,你就去调用了! 一般的注解没加,bean的名字写错都好检查,但是逻辑错误就需要看清自己的思维过程了. 实例:在使用ActiveMq的过程中,第一步对Ac ...

  9. C++用递归方式实现在对不更改随机数组的情况下查找最大值

    #include <iostream> #include <iomanip> #include <ctime> using namespace std; int M ...

  10. poi jar包的作用

    目前POI的最新发布版本是3.10_FINAL.该版本保护的jar包有: Maven artifactId Prerequisites JAR poi commons-logging, commons ...