zoukankan      html  css  js  c++  java
  • C#winform判断鼠标30秒不动就关闭窗口

        public partial class BaseForm : Form
        {
            private Timer timer;
            int x, y;
            DateTime start;
            bool ff = true; 
    
            public BaseForm()
            {
                timer = new Timer();
    
                x = Control.MousePosition.X;
                y = Control.MousePosition.Y;
    
                timer.Interval = 1000;
                timer.Tick += new EventHandler(timer_Tick);
                timer.Start();
            }
    
            protected void timer_Tick(object sender, EventArgs e)
            {
                int x1 = Control.MousePosition.X;
                int y1 = Control.MousePosition.Y;
    
                if ((x == x1) && (y == y1) && ff)
                {
                    start = DateTime.Now;
                    ff = false;
                }
                if (x != x1 || y != y1)
                {
                    x = x1;
                    y = y1;
                    start = DateTime.Now;
                    ff = true;
                }
                TimeSpan ts = DateTime.Now.Subtract(start);
                if (ts.Seconds > 5) Environment.Exit(0);  //把5改成30,就是30秒
            }
    
            protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
            {
                start = DateTime.Now;
                return base.ProcessCmdKey(ref msg, keyData);
            }
        }
    
    本博客有部分内容来自网络,如有问题请联系:hebeilijianghua@qq.com,并注明来自博客园。
  • 相关阅读:
    2019春招面试题总结-03
    2019春招面试题总结-02
    2019春招面试题总结-01
    Node.js 全局对象
    Node.js 路由
    Node.js 函数
    Node.js 模块系统
    Node.js Stream(流)
    Node.js Buffer(缓冲区)
    Node.js EventEmitter
  • 原文地址:https://www.cnblogs.com/leebokeyuan/p/7395491.html
Copyright © 2011-2022 走看看