Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Windows 8 touch support to existing WinForms application

I have an existing Windows Forms desktop application targeting .NET Framework 4 and would like to add Windows 8 touch support to it.

Currently the program works fine in Windows 8, and I can potentially just resize some of the elements to make it more user-friendly on touch devices. However, adding gestures such as pinch-to-zoom on datagrids, and swipe support for other elements would go a long way to making the application more modern in a touch-only environment.

I'm investing in Visual Studio 2012, which will let me target .NET 4.5 and the new Windows 8 features, but does anyone know of any resources which would help me with updating my application? I'm specifically concerned about the following:

  • Inability to directly test the touch features of the application on my non-touch development machine. Microsoft's simulator only seems to support Metro apps. I've heard that tablet apps such as Splashtop can help (I have an Android tablet), but haven't seen anything concrete for this particular scenario
  • Whether gestures are even supported on WinForms applications. Am I going to have to upgrade the entire UI to WPF to get this working? (If I did go this route, I believe I could also target Windows 7, as multi-touch is supported on WPF 4)
  • Detecting the device's touch support at runtime and scaling/changing the UI appropriately, similar to the Touch mode setting on Microsoft's Windows RT Office apps. I don't want to fork the project just to add the new features
  • Automated testing of touch interactions

This isn't an exhaustive list by any means, but I'd really appreciate any advice from those who may have approached a similar upgrade in the past.

like image 564
Dave R. Avatar asked Nov 09 '12 13:11

Dave R.


People also ask

Does Microsoft support WinForms?

Windows Forms (WinForms) is a free and open-source graphical (GUI) class library included as a part of Microsoft .

Are Windows Forms cross platform?

NET Framework offered Windows Presentation Foundation (WPF) and Windows Forms (WinForms) as the main UI options, the cross-platform .


2 Answers

You can use TouchToolkit for WinForms from component one. However I think you'll have to rewrite your application to use these components.

enter image description here

like image 51
Preet Sangha Avatar answered Oct 26 '22 12:10

Preet Sangha


Regarding the comment on "Inability to directly test the touch features of the application on my non-touch development machine. Microsoft's simulator only seems to support Metro apps" - I am able to run the simulator, go to the desktop in the simulator and run any app while simulating touch input - that's including WinForms apps.

Since WinForms is just a wrapper over WinAPI's native UI APIs - you can use p/Invoke to use the touch APIs that I think were added around Vista/Windows 7 timeframe. Mainly the WM_TOUCH and WM_GESTURE messages. There are plenty of examples for p/Invoking and using protected override void WndProc(ref Message m) which are the main things you'd need to handle touch. Other than that - touch inputs are by default automatically promoted to mouse events when not handled as touch, so a lot of things just work.

like image 36
Filip Skakun Avatar answered Oct 26 '22 12:10

Filip Skakun