一个WPF控件 诡异的MouseEvent 。
2024-08-24 04:21:40
背景:
private System.Windows.Controls.Border _borderTouch;
private bool _mouseDown = false;
private System.Windows.Point _currentPoint = new System.Windows.Point(0, 0);
private System.Windows.Point _lastPoint = new System.Windows.Point(0, 0);
一个wpf Border控件,然后注册鼠标事件
touch.MouseLeftButtonDown += new MouseButtonEventHandler(touch_MouseLeftButtonDown);
touch.MouseLeftButtonUp += new MouseButtonEventHandler(touch_MouseLeftButtonUp);
touch.MouseLeave += new MouseEventHandler(touch_MouseLeave);
touch.MouseMove += new MouseEventHandler(touch_MouseMove);
private void touch_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
//if (this._mouseDown)
//{
this._mouseDown = false;
//}
}
private void touch_MouseLeave(object sender, MouseEventArgs e)
{
//if (this._mouseDown)
//{
this._mouseDown = false;
//}
}
private void touch_MouseMove(object sender, MouseEventArgs e)
{
if (this._mouseDown)
{
_currentPoint = e.GetPosition(this._borderTouch);
//if (_currentPoint == _lastPoint) return;
//_lastPoint = _currentPoint;
}
}
private void touch_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (!this._mouseDown)
{
this._mouseDown = true;
_currentPoint = e.GetPosition(this._borderTouch);
//_lastPoint = _currentPoint;
}
}
操作过程:
1. 点鼠标左键触发touch_MouseLeftButtonDown一次,
2. 然后移动鼠标触发touch_MouseMove(注明:如果鼠标在某点不动,相同坐标只触发一次,然后事件不再触发,如果再移动接触发),
3. 鼠标离开(或者左键松开)触发touch_MouseLeave(touch_MouseLeftButtonUp)一次。
问题:
1. 在我的电脑上对应以上操作过程包括触发事件的次数。
我的电脑配置:
2. 但是在第二个电脑上就不一样,
第2个过程鼠标不动的时候会触发10多次然后就不触发啦(也就是说相同的坐标会触发10多次touch_MouseMove然后不再触发)
第3个过程也是触发10多次,然后停止触发。
第二个电脑配置:
解决:
我想要的当然是我电脑上的正常操作过程,为同步另一台电脑。
我改啦下代码,但是我不知道为什么会有这样的差异。
1. touch_MouseMove 添加判断上一次的坐标和现在的坐标是否相同,如果相同就return
if (_currentPoint == _lastPoint) return;
_lastPoint = _currentPoint;
2. touch_MouseLeftButtonUp/touch_MouseLeave 添加判断
if (this._mouseDown)
{
this._mouseDown = false;
}
最新文章
- JavaScript(二) DOM
- 跨平台的加密算法XXTEA 的封装
- jeecms附件标签用法
- SQL Server 在线进程分析处理
- Android仿微信SlideView聊天列表滑动删除效果
- iOS越狱开发手记 - iOS9.3 dyld_decache不能提取arm64的dyld的解决方法
- 维护Study
- webpack打包编译时,不识别src目录以外的js或css
- Exceptionless 本地部署踩坑记录
- RGBA 和 opacity的区别
- 接口和抽象类的区别(JDK1.8)
- ORALCE删除临时表空间的方法---解决ORA01033: oralce initialization or shutdown in progress方案
- ORA-12541:TNS:无监听程序
- 利用Kettle 从Excel中抽取数据写入SQLite
- 开源播放器 ijkplayer (一) :使用Ijkplayer播放直播视频
- HTTP接口-跨域-callback
- 应对新型“蠕虫”式比特币勒索软件“wannacry”的紧急措施
- ie10以上媒体查询 css
- 连接数据库-stone
- Java机器学习框架deeplearing4j入门教程
热门文章
- SQLServer(MSSQL)、MySQL、SQLite、Access相互迁移转换工具 DB2DB v1.3
- MVC+EF 理解和实现仓储模式和工作单元模式
- 东大OJ-1391-Big big Power
- Spring学习进阶(四) Spring JDBC
- Yii2 使用小部件 Breadcrumbs
- morris的用法
- 'hibernate.dialect' must be set when no Connection avalable’
- Elasticsearch: Indexing SQL databases. The easy way
- react.js 之 批量添加与删除功能
- jquery-焦点定位追加内容