前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >WPF 获得触摸精度和触摸点

WPF 获得触摸精度和触摸点

作者头像
林德熙
发布2018-09-18 17:15:58
8920
发布2018-09-18 17:15:58
举报
文章被收录于专栏:林德熙的博客林德熙的博客

本文主要告诉大家如何获得所有的触摸设备的触摸精度和触摸点数。

需要通过反射的方法才可以拿到触摸的精度。

使用 Tablet.TabletDevices 可以获得所有的触摸设备,获得触摸点数可以通过下面代码

代码语言:javascript
复制
foreach (TabletDevice device in Tablet.TabletDevices)
{
	Console.WriteLine("触摸点数" + device.StylusDevices.Count);//触摸点数
}

触摸精度就需要使用反射

代码语言:javascript
复制
        var builder = new StringBuilder();
                foreach (TabletDevice device in Tablet.TabletDevices)
                {
                    var deviceProperty = typeof(TabletDevice).GetProperty("TabletDeviceImpl",
                        BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty);
                    var deviceImpl = deviceProperty is null ? device : deviceProperty.GetValue(device);
                    var info = deviceImpl.GetType().GetProperty("TabletSize",
                        BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty);

                    var tabletSize = (Size) info.GetValue(deviceImpl, null);
                    if (device.Type == TabletDeviceType.Touch)
                    {
                        builder.Append(string.Format("{1}:{2} 点触摸,精度 {3}{0}", Environment.NewLine,
                            device.Name, device.StylusDevices.Count, tabletSize));
                    }
                    else
                    {
                        builder.Append(string.Format("{1}:{2} 个触笔设备,精度 {3}{0}", Environment.NewLine,
                            device.Name, device.StylusDevices.Count, tabletSize));
                    }
                }

如果发现设备触摸失效,可以使用这个项目

ManipulationDemo


本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档