• WinForm 实现最小化任务栏托盘


    步骤:

    1. 在Form上添加一个 NotifyIcon 控件,无需设置属性,当时如果想要在最小化到任务栏可以点右键菜单,那还需要添加一个ContextMenuStrip菜单控件,然后把 NotifyIcon的ContextMenuStrip属性设置为菜单控件即可。

    2.在 NotifyIcon  的DoubleClick 事件里,添加以下代码:

    private void mainNotifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                //双击显示主界面
                if (this.Visible)
                {
                    this.WindowState = FormWindowState.Minimized;
                    this.mainNotifyIcon.Visible = true;
                    this.Hide();
                }
                else
                {
                    this.Visible = true;
                    this.WindowState = FormWindowState.Normal;
                    this.Activate();
                }
            }

    3.在窗体 Form 的Closing 事件添加以下代码:

    private void frMain_FormClosing(object sender, FormClosingEventArgs e)
            {
                // 注意判断关闭事件reason来源于窗体按钮,否则用菜单退出时无法退出!
                if (e.CloseReason == CloseReason.UserClosing)
                {
                    //取消"关闭窗口"事件
                    e.Cancel = true; // 取消关闭窗体 
    
                    //使关闭时窗口向右下角缩小的效果
                    this.WindowState = FormWindowState.Minimized;
                    this.mainNotifyIcon.Visible = true;
                    //this.m_cartoonForm.CartoonClose();
                    this.Hide();
                    return;
                } 
            }

    这样就搞定了。

  • 相关阅读:
    xampp服务器搭建和使用
    使用proxyee-down解决百度云下载限速问题
    iOS开发之多线程技术—GCD篇
    iOS 将视频流(h264)和音频流封装成PS流
    iOS 播放音频文件
    iOS 简单socket连接
    ios获取本机网络IP地址方法
    iOS10适配相关
    iOS设备的尺寸和分辨率
    理解NodeJS
  • 原文地址:https://www.cnblogs.com/lpq21314/p/9475207.html
Copyright © 2020-2023  润新知