技术开发 频道

挑战iphone 实战Windows 7多点触摸应用

  接下来插入Window Load事件:

// check to see whether multitouch is enabled

  
if (IsMultitouchEnabled)

  {

  
// enables stylus events for processor manipulation

  Factory.EnableStylusEvents(
this);

  
// add the stylus events

  StylusDown
+= (s, e) =>

  {

  manipulationProcessor.ProcessDown((uint)e.StylusDevice.Id, e.GetPosition(
this).ToDrawingPointF());

  };

  StylusUp
+= (s, e) =>

  {

  manipulationProcessor.ProcessUp((uint)e.StylusDevice.Id, e.GetPosition(
this).ToDrawingPointF());

  };

  StylusMove
+= (s, e) =>

  {

  manipulationProcessor.ProcessMove((uint)e.StylusDevice.Id, e.GetPosition(
this).ToDrawingPointF());

  };

  
// register the ManipulationDelta event with the manipulation processor

  manipulationProcessor.ManipulationDelta
+= ProcessManipulationDelta;

  
// set the rotation angle for single finger manipulation

  manipulationProcessor.PivotRadius
= 2;

  }

    在事件处理程序块部分编写你的逻辑,我这里实现了旋转,缩放和图像定位功能,代码如下:

private void ProcessManipulationDelta(object sender, ManipulationDeltaEventArgs e)

  {

  trTranslate.X
+= e.TranslationDelta.Width;

  trTranslate.Y
+= e.TranslationDelta.Height;

  trRotate.Angle
+= e.RotationDelta * 180 / Math.PI;

  trScale.ScaleX
*= e.ScaleDelta;

  trScale.ScaleY
*= e.ScaleDelta;

  }

    小结

  从ManipulationDeltaEventArgs你可以得到不同的值,根据这些值你可以在这个块中实现你自己的功能,TranslateTransform实现图像定位,RotateTransform实现图像旋转,ScaleTransform调整图像的大小。现在可以运行你的项目,测试你的第一个多点触摸应用程序。

查看原文  

  原文名:Windows 7 Multitouch Application Development (Part - I)

0
相关文章