Click here to Skip to main content
15,886,422 members
Articles / Programming Languages / C#

Finger Gesture Support for the Compact Framework

Rate me:
Please Sign up or sign in to vote.
2.54/5 (6 votes)
10 May 2009CPOL 29K   12   9
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 2 Pin
toms21-Sep-09 22:45
professionaltoms21-Sep-09 22:45 
it's just a snipped.
GeneralThis is great! Pin
gciochina20-May-09 23:05
gciochina20-May-09 23:05 
GeneralRe: This is great! Pin
VbGuru61323-Jun-09 9:13
VbGuru61323-Jun-09 9:13 
GeneralMy vote of 1 Pin
Not Active11-May-09 3:09
mentorNot Active11-May-09 3:09 
GeneralSimilar solution but making use of the Unit Circle. Pin
M.K.A. Monster10-May-09 19:14
M.K.A. Monster10-May-09 19:14 
GeneralRe: Similar solution but making use of the Unit Circle. Pin
Not Active11-May-09 3:13
mentorNot Active11-May-09 3:13 
GeneralRe: Similar solution but making use of the Unit Circle. Pin
VbGuru61311-May-09 6:05
VbGuru61311-May-09 6:05 
GeneralMy vote of 1 Pin
MohammadAmiry10-May-09 18:39
MohammadAmiry10-May-09 18:39 
GeneralRe: My vote of 1 Pin
VbGuru61311-May-09 2:45
VbGuru61311-May-09 2:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.