Develop Multi-Point programs in WPF

Source: Internet
Author: User

Experience: develop multiple points using WPFProgramIt makes me feel very simple, and it all proves Microsoft's strength.

Step 1: Open vs2010 and create a wpfapplication1 Program

Step 2: Add a canvas and add the touchdown, touchmove, and touchup events to the canvas.

For example, <canvas background = "gray" name = "canvas1" Touchdown = "canvas1_touchdown"
Touchmove = "canvas1_touchmove" touchup = "canvas1_touchup"/>

Step 3: Define a digital dictionary storage object:

Private dictionary <int, ellipse> ellipses = new dictionary <int, ellipse> ();

Add the following to the three events:Code:

Private void canvas1_touchdown (Object sender, toucheventargs E)
{
Ellipse ellipse = new ellipse ();
Ellipse. width = 50;
Ellipse. Height = 50;
Ellipse. Stroke = brushes. yellowgreen;
Touchpoint = E. gettouchpoint (this. canvas1 );
Canvas. settop (ellipse, touchpoint. bounds. Top );
Canvas. setleft (ellipse, touchpoint. bounds. Left );
Ellipses [E. touchdevice. ID] = ellipse;
This. canvas1.children. Add (ellipse );
}

Private void canvas1_touchmove (Object sender, toucheventargs E)
{
Ellipse ellipse = ellipses [E. touchdevice. ID];
Touchpoint = E. gettouchpoint (this. canvas1 );
Canvas. settop (ellipse, touchpoint. bounds. Top );
Canvas. setleft (ellipse, touchpoint. bounds. Left );

}

Private void canvas1_touchup (Object sender, toucheventargs E)
{
Ellipse ellipse = ellipses [E. touchdevice. ID];
Ellipses. Remove (E. touchdevice. ID );
This. canvas1.children. Remove (ellipse );
}

Compile and run OK. You can download a multi-point simulator with multi-point touch screen hardware.

 

The effect is as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.