如何判断哪个物理设备点击了 C# 中的按钮?
我有一个带有按钮的表单。该应用程序旨在在触摸屏计算机上运行。单击按钮时,我想知道是通过鼠标单击还是通过触摸屏单击。
这可能吗?如果是这样,怎么办?
I have a Form with buttons. This application is meant to run on a touchscreen computer. When a button is clicked I would like to know whether it was clicked by the mouse or the touchscreen.
Is this possible? If so, how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一种粗俗的方法,因为只要按钮被鼠标之外的其他东西“单击”,无论是触摸屏还是键盘的返回,它都会捕获异常。但它会完成这项工作:)
This is a gross way to do it, because it will catch an exception anytime button is "clicked" by something else than the mouse, either touchscreen or keyboard's return. But it will do the job :)
以这种方式从 Wildhorn 的答案中获取可以避免抛出异常:
这没有太大不同,但您没有异常处理的开销。您也可以尝试多次演员表,直到获得正确的演员表。
Taking from Wildhorn's answer this way avoids the exceptions being thrown:
It's not much different but you don't have the overhead of the exception handling. Also you could try multiple casts til you got the right one.