Windows 7 Development: Multi-point touch

Source: Internet
Author: User
Tags touch

(Code fragment –multitouch–picturetrackermanagerclass VB)

Visual Basic

Imports system.windows


Imports System.Windows.Controls





Class Picturetrackermanager


' Map between touch IDs and picture trackers


Private ReadOnly _picturetrackermap as New Dictionary (of Integer, Picturetracker)


Private ReadOnly _canvas as Canvas


public Sub New (ByVal canvas as Canvas)


_canvas = Canvas


End Sub


public Sub Processdown (ByVal sender as Object, ByVal args as StylusEventArgs)


Dim location = args. GetPosition (_canvas)


Dim picturetracker = Getpicturetracker (args. Stylusdevice.id, location)





If Picturetracker is no Then return





Picturetracker.processdown (location)


End Sub


public Sub Processup (ByVal sender as Object, ByVal args as StylusEventArgs)


Dim location = args. GetPosition (_canvas)


Dim picturetracker = Getpicturetracker (args. Stylusdevice.id)


If Picturetracker is no Then return





picturetracker.processup (location)


_picturetrackermap.remove (args. Stylusdevice.id)


End Sub


public Sub Processmove (ByVal sender as Object, ByVal args as StylusEventArgs)


Dim picturetracker = Getpicturetracker (args. Stylusdevice.id)


If Picturetracker is no Then return





Dim location = args. GetPosition (_canvas)


picturetracker.processmove (location)


End Sub


Private Function Getpicturetracker (ByVal TouchID as Integer) as Picturetracker


Dim Picturetracker as Picturetracker = Nothing


_picturetrackermap.trygetvalue (TouchID, Picturetracker)


return Picturetracker


End Function


Private Function getpicturetracker (ByVal TouchID as Integer, ByVal location as point) as Picturetracker


Dim Picturetracker as Picturetracker = Nothing





' If we already track the picture with the TouchID


If _picturetrackermap.trygetvalue (TouchID, Picturetracker) Then return Picturetracker





' Get the "picture under" Touch location


Dim picture = findpicture (location)


If picture are nothing Then return nothing





' The ' if we track the picture with the other ID


Picturetracker = (from entry in _picturetrackermap _


Where entry. Value.picture is picture _


Select entry. Value). FirstOrDefault ()





'


If Picturetracker is nothing Then


' Create new


Picturetracker = New picturetracker ()


picturetracker.picture = Picture


Bringpicturetofront (picture)


End If


' Remember The corelation between the Touch ID and the picture


_picturetrackermap (TouchID) = Picturetracker


return Picturetracker


End Function


' ' <summary>


"Find the" picture "in" Touch location


' ' </summary>


' <param name= "PointF" >touch location</param>


' <returns>the picture or null if no to the exists in the touch


' ' location</returns>


Private Function findpicture (ByVal location as point) as the picture


Dim result = Visualtreehelper.hittest (_canvas, location)


If result are nothing Then return nothing





Dim image = TryCast (result. Visualhit, Image)


If image is no Then return nothing





return TryCast (image. Parent, picture)


End Function


Private Sub Bringpicturetofront (ByVal picture as picture)


If picture is no Then return





Dim children = (from child in _canvas. Children _


Where Child IsNot Picture _


ORDER by Canvas.getzindex (child) _


Select Child). ToArray ()





for i = 0 to children. Length-1


Canvas.setzindex (Children (i), i)


Next i


Canvas.setzindex (picture, children. Length)


End Sub


End Class

Related Article

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.