是否有可能让我的c#wpf程序知道用户是否有触摸屏?

KDP*_*KDP 12 c# wpf touchscreen touch login-control

我有一个登录应用程序,它有一个刷卡系统,人们只有在有触摸屏时才能使用.他们可以通过刷他们的个人模式滑动代码登录.

如果用户有触摸屏,是否可以签入C#或WPF?即使他当时没有使用触控功能?

小智 19

在C#代码中,通过using System.Windows.Input命名空间查找是否存在触摸屏(不检查是否是单个或多点触摸设备)PresentationCore.

    public bool HasTouchInput()
    {
        foreach (TabletDevice tabletDevice in Tablet.TabletDevices)
        {
            //Only detect if it is a touch Screen not how many touches (i.e. Single touch or Multi-touch)
            if(tabletDevice.Type == TabletDeviceType.Touch)
                return true;
        }

        return false;
    }
Run Code Online (Sandbox Code Playgroud)

  • 15人测试了答案,它的确有效.为什么没有标记为正确答案? (2认同)

Sim*_*sen 1

我认为托管代码中没有任何可用的内容,但您可以在Win32_DesktopMonitor. 有关详细信息,请参阅msdn

我发现这篇博文可能会有所帮助,即使它是在 Windows CE 上:http://blog.nerdbank.net/2006/10/platform-detection-iii-how-to-detect.html