Pretend I have 2 monitors. Primary display is just a normal PC desktop monitor, the other other one is a touchscreen. When I load a program (WinForm, WPF, ...), it will load on the primary monitor.
Question: if I replace the program to the touchscreen, how can I know if the current screen/display/monitor is a touchscreen or has touch enabled?
In other words, how can I detect the current screen/display/monitor and its settings?
So far i worked with the Screen
class (Windows.Forms), Tablet
Class (Windows.Input) and with DLLImport
of User32.dll (GetSystemMetrics()). None of them or a combination of them works.
I want something to find like: Monitor.Current.IsTouch
or Display.CurrentDisplay.TouchEnabled
I don't have a touch screen to test this on, but you can probably use System.Windows.Input.Tablet to enumerate through the static TabletDevices property. The ActiveSource property can be compared against PresentationSource.FromVisual to see if your UIElement is on the TabletDevice. This may not be perfect, I'm not used to using these classes, but that should get you on the right track. TabletDevices also have a Name property which you may be able to compare against System.Windows.Forms.Screen.DeviceName.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With