Alteridem.WinTouch 0.1.1

dotnet add package Alteridem.WinTouch --version 0.1.1
NuGet\Install-Package Alteridem.WinTouch -Version 0.1.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Alteridem.WinTouch" Version="0.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Alteridem.WinTouch --version 0.1.1
#r "nuget: Alteridem.WinTouch, 0.1.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Alteridem.WinTouch as a Cake Addin
#addin nuget:?package=Alteridem.WinTouch&version=0.1.1

// Install Alteridem.WinTouch as a Cake Tool
#tool nuget:?package=Alteridem.WinTouch&version=0.1.1

WinTouch.NET

WinTouch.NET is a .NET library for handling Windows 7 Touch Gestures in a WinForms application.

It allows you to handle the following gestures,

  • Pan
  • Rotate
  • Zoom
  • Two Finger Tap
  • Press and Tap

For more information on Windows Gestures, see Windows Touch Gestures Overview on MSDN.

The library has the following features,

  • Fails gracefully on operating systems older than Windows 7
  • Compiled against .NET 2.0 for maximum compatibility
  • Allows you to subscribe to just the events that you are interested in.

Usage

  1. Add a reference to WinTouch.dll to your project.
  2. Create a GestureListener passing in the control you want to receive touch events for.
  3. Optionally pass in a collection of GestureConfig objects to the GestureListener constructor to specify which gestures you want it to capture events for. By default, it captures GestureConfigurationFlag.GC_ALLGESTURES.
  4. On the GestureListener object you created, subscribe to the gesture events that you are interested in. It supports Pan, PressAndTap, Rotate, TwoFingerTap and Zoom.

For a demo on how to use the library, see the Demo project on GitHub. Here is an example,

public partial class GestureControl : UserControl
{
    // Our touch listener
    private readonly GestureListener _gesture;

    // Size, location and rotation of the image
    private Point _location;
    private int _size;
    private double _rotation;

    // An image to draw
    private Image m_image;

    // Brushes
    private readonly Brush[] _backBrushes = { Brushes.White, Brushes.AntiqueWhite, Brushes.Bisque, Brushes.Wheat, Brushes.Bisque, Brushes.AntiqueWhite };
    private int _backBrush;

    public GestureControl()
    {
        InitializeComponent();

        SetStyle( ControlStyles.AllPaintingInWmPaint |
                    ControlStyles.UserPaint |
                    ControlStyles.ResizeRedraw |
                    ControlStyles.OptimizedDoubleBuffer, true );

        // Subscribe to all the touch events
        _gesture = new GestureListener( this );
        _gesture.Pan += OnPan;
        _gesture.PressAndTap += OnPressAndTap;
        _gesture.Rotate += OnRotate;
        _gesture.TwoFingerTap += OnTwoFingerTap;
        _gesture.Zoom += OnZoom;

        m_image = Properties.Resources.windows_logo;
    }

    private void OnLoad( object sender, EventArgs e )
    {
        ResetImage();
    }

    private void ResetImage()
    {
        // Center the image on the form and make it half the width
        // of the shortest side
        _size = Math.Min( Width, Height ) / 2;
        _location = new Point( Width / 2, Height / 2 );
        _rotation = 0;
    }

    void OnPan( object sender, PanEventArgs e )
    {
        string msg = string.Format( "Pan Loc:({0},{1}) InertiaVector:({2},{3})", e.Location.X, e.Location.Y,
                                    e.InertiaVector.X, e.InertiaVector.Y );
        Debug.WriteLine( msg );

        if ( !e.Begin )
        {
            _location.Offset( e.PanOffset );

            // Make sure it doesn't leave the screen
            if ( _location.X < 0 )
                _location.X = 0;
            else if ( _location.X > Width )
                _location.X = Width;

            if ( _location.Y < 0 )
                _location.Y = 0;
            else if ( _location.Y > Height )
                _location.Y = Height;

            Invalidate();
        }
    }

    void OnPressAndTap( object sender, PressAndTapEventArgs e )
    {
        string msg = string.Format( "PressAndTap Loc:({0},{1}) Distance:{2})", e.Location.X, e.Location.Y, e.Distance );
        Debug.WriteLine( msg );

        if ( e.Begin )
        {
            if ( ++_backBrush >= _backBrushes.Length )
            {
                _backBrush = 0;
            }
            Invalidate();
        }
    }

    void OnRotate( object sender, RotateEventArgs e )
    {
        string msg = string.Format( "Rotate Loc:({0},{1}) Angle:{2}", e.Location.X, e.Location.Y, e.TotalDegrees );
        Debug.WriteLine( msg );

        if ( !e.Begin && !e.End )
        {
            _rotation -= e.Degrees;
            Invalidate();
        }
    }

    void OnTwoFingerTap( object sender, TwoFingerTapEventArgs e )
    {
        string msg = string.Format( "TwoFingerTap Loc:({0},{1}) Distance:{2}", e.Location.X, e.Location.Y, e.Distance );
        Debug.WriteLine( msg );

        if ( e.Begin )
        {
            ResetImage();
            Invalidate();
        }
    }

    void OnZoom( object sender, ZoomEventArgs e )
    {
        string msg = string.Format( "Zoom Loc:({0},{1}) Distance:{2}", e.Location.X, e.Location.Y, e.Distance );
        Debug.WriteLine( msg );

        if ( !e.Begin )
        {
            _size = (int)(_size * e.PercentChange);
            Invalidate();
        }
    }

    protected override void OnPaint( PaintEventArgs e )
    {
        // Draw Background
        e.Graphics.FillRectangle( _backBrushes[_backBrush], 0, 0, Width, Height );

        // Draw Info
        string info = string.Format( "Pos:{0} Size:{1} Rotation:{2}", _location, _size, _rotation );
        e.Graphics.DrawString( info, SystemFonts.DefaultFont, Brushes.Black, 5, 5 );

        // Draw Square
        e.Graphics.TranslateTransform( _location.X, _location.Y );
        e.Graphics.RotateTransform( (float)_rotation );
        e.Graphics.TranslateTransform( -_location.X, -_location.Y );
        e.Graphics.DrawImage( m_image, _location.X - _size / 2, _location.Y - _size / 2, _size, _size );
    }
}
Product Compatible and additional computed target framework versions.
.NET Framework net20 is compatible.  net35 was computed.  net40 was computed.  net403 was computed.  net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.1 2,667 2/11/2021
0.1.0 4,259 12/5/2014