winform 判断鼠标在一段时间内是否移动 分类: .NET 2012-04-06 15:40 1236人阅读 评论(2) 收藏
int x, y; DateTime start; public Form1() { InitializeComponent(); x = Control.MousePosition.X; y = Control.MousePosition.Y; this.timer1.Enabled = true; this.timer1.Interval = 1000; } #region 判断鼠标在1分钟内是否移动 bool ff = true; private void timer1_Tick_1(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); //鼠标或键盘误动作1分钟后开始播放视频 if (ts.Minutes >= 1) { //do something } }
版权声明:本文为博主原创文章,未经博主允许不得转载。