如何获得触摸屏使用鼠标事件,而不是触摸事件在C#应用程序 [英] How to get Touchscreen to use Mouse Events instead of Touch Events in C# app

查看:3547
本文介绍了如何获得触摸屏使用鼠标事件,而不是触摸事件在C#应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了覆盖PreviewMouseUp,PreviewMouseMove和PreviewMouseDown事件在一些自定义的控制,允许通过单击并拖动滚动滚动观众一个C#应用程序。当使用鼠标拖动和滚动此自定义代码的工作在非触摸屏伟大的,但是当我使用一个真正的触摸屏上监视它不能正常工作,因为当显示器被触摸和拖PreviewMouseUp不被解雇一个手指。

I have developed a C# app that overrides the PreviewMouseUp, PreviewMouseMove, and PreviewMouseDown events in some custom controls to allow scrolling a scroll viewer by clicking and dragging. This custom code works great on non-touch screens when the mouse is used to drag and scroll, but when I use it on a real touch screen monitor it fails to work because the PreviewMouseUp does not get fired when the monitor is touched and dragged with a finger.

我希望能够用我的现有代码最小的变化。这将允许我使用鼠标单击/拖动,而在我的笔记本电脑进行调试,并使用触摸屏触摸/拖动。

I want to be able to use my existing code with minimal changes. This would allow me to use the mouse to click/drag while debugging on my laptop, and use the touch screen to touch/drag.

反正是有配置Windows 7的电脑把所有的触摸(PreviewTouchUp,的PreviewTouchDown和PreviewTouchMove)作为鼠标事件呢?

Is there anyway to configure a windows 7 computer to treat all touches (PreviewTouchUp, PreviewTouchDown, and PreviewTouchMove) as mouse events instead?

更新:我忘了​​提。我认为,如果触摸事件不处理,比.NET自动提高鼠标事件之后。这不会出现以上问题,即使没有我写的代码目前处理触摸事件。任何想法,为什么这可能是发生?

UPDATE: I forgot to mention. I thought that if the Touch events are not handled, than .NET automatically raises the Mouse events afterwards. This does not appear to be happening even though none of the code I wrote handles the Touch Events currently. Any ideas why this may be happening?

谢谢,
布赖恩

Thanks, brian

推荐答案

你可以做的就是用同样的方法为,是这样的:

What you can do is to use the same method for both, something like this:

protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
{
    OnPreviewTouchMouseUp(e);
}

protected override void OnPreviewTouchUp(TouchEventArgs e)
{
    OnPreviewTouchMouseUp(e);
}

private void OnPreviewTouchMouseUp(EventArgs e)
{

}

唯一的区别是你得到的鼠标/触摸的坐标的方式:

The only difference will be the way you get the coordinates of the mouse/touch:

有关触摸:

e.GetTouchPoint(this).Position;

有关鼠标:

e.GetPosition(this);

这篇关于如何获得触摸屏使用鼠标事件,而不是触摸事件在C#应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆