Yeonju Cho
Yeonju Cho

Reputation: 13

How can I get the touch input(positions on the screen) on the Windows Surface Pro when writing the application in c#?

I am very very beginner of C# programming. The previous program that I made can get touch input as a click event on the Surface Pro. So, It cannot get multi-touch input. How can I get the multi-touch inputs(positions on the screen) on the Windows Surface Pro when writing the application in c#?

I heard that I can use touch class, but I never know how to use it .... I am struggling with this for 2 weeks, but could not make any progress.

Anyone who can explain how to use touch class specifically? Or any other suggestions to get touch input values from the Surface pro touch panel?

Upvotes: 1

Views: 4187

Answers (1)

kennyzx
kennyzx

Reputation: 12993

Assuming you are programming WPF.

Register UIElement.TouchDown event, for example, in you MainWindow's constructor, add

this.TouchDown += MainWindow_TouchDown;

If multiple fingers are touching screen at the same time, the TouchDown event is fired for each finger.

You can get the position of the touch (relative to screen) from the TouchEventArgs which is passed as an argument to the event handler.

void MainWindow_TouchDown(object sender, TouchEventArgs e)
{
    TouchPoint pointFromWindow = e.GetTouchPoint(this); //relative to Top-Left corner of Window
    Point locationFromScreen = this.PointToScreen(new Point(pointFromWindow.Position.X, pointFromWindow.Position.Y)); //translate to coordinates relative to Top-Left corner of Screen
}

Note: .NET 4.0 is required, Windows 8 shipped with .NET 4.0 pre-installed. If you are running on Windows 7, you have to ensure it is installed.

Upvotes: 1

Related Questions