Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
Print
(untagged)

Finger Gesture Support for the Compact Framework

0.00/5 (No votes)
10 May 2009 1  
An article on finger gesture support for a Pocket PC app.

Introduction

Getting your Windows Mobile application to compete with the iPhone can be difficult. Here is a quick way to get the finger gesture support on your Windows Forms. This little snippet can integrate four way gesture support for your Mobile app.

Using the Code

Just copy and paste the class level variables and the two events, and instantly you will have gesture support.

C#
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" );
            }
        }
    }
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here