Compact Framework 的手指手势支持
一篇关于 Pocket PC 应用的手指势态支持的文章。
引言
让你的 Windows Mobile 应用程序与 iPhone 竞争可能很困难。这里有一个快速的方法,可以在你的 Windows Forms 上获得手指势态支持。这个小片段可以为你的移动应用程序集成四向势态支持。
Using the Code
只需复制并粘贴类级别变量和两个事件,你就能立即获得势态支持。
public partial class Form1 : Form
{
private int startPositionY = 0;
private int startPositionX = 0;
//Configurable Points for your device so you can support
//different screen sizes . This would work on a 240x320
// To support a 320x240 you can switch the values
// to support a 240x240 make them both 25
private const int Touch_ThresholdY = 100;
private const int Touch_ThresholdX = 25;
public Form1()
{
InitializeComponent();
}
private void Form1_MouseDown( object sender, MouseEventArgs e)
{
startPositionY = e.Y;
startPositionX = e.X;
}
private void Form1_MouseUp( object sender, MouseEventArgs e)
{
if (startPositionX > e.X && startPositionY < e.Y)
{
if ((e.Y - startPositionY) > Touch_ThresholdY)
{
MessageBox .Show(\cf4 "Finger Down" );
}
else if ((startPositionX - e.X) > Touch_ThresholdX)
{
MessageBox .Show(\cf4 "Finger Left" );
}
}
else if (startPositionX < e.X && startPositionY > e.Y)
{
if ((startPositionY - e.Y) > Touch_ThresholdY)
{
MessageBox .Show(\cf4 "Finger Up" );
}
else if ((e.X - startPositionX) > Touch_ThresholdX)
{
MessageBox .Show(\cf4 "Finger Right" );
}
}
}
}