Click here to Skip to main content
15,891,607 members
Articles / Multimedia / GDI+

C# Application to Create and Recognize Mouse Gestures (.NET)

Rate me:
Please Sign up or sign in to vote.
4.82/5 (39 votes)
17 Mar 2008CPOL5 min read 221.8K   8.1K   144  
This program can create and recognize mouse gestures.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MouseGestures;

namespace GestureRecognizer
{
	public partial class GestureSetCreationForm : Form
	{
		private GestureMainForm m_MainForm;
		private GestureRecognizerData m_Data;
        private GestureSet m_GestureSet;

		public int BaseGestureIndex { get { return BaseGestureComboBox.SelectedIndex - 1; } }
		public bool ClearGestureSet { get { return ClearGestureSetCheckBox.Checked; } }

		public GestureSetCreationForm(GestureMainForm main_form, GestureRecognizerData data, GestureSet set)
		{
			InitializeComponent();
			m_MainForm = main_form;
			m_Data = data;
            m_GestureSet = set;

			BaseGestureComboBox.Items.Add(data.Gesture.Name);
            for (int i = 0; i < m_GestureSet.Gestures; i++)
                BaseGestureComboBox.Items.Add(m_GestureSet[i].Name);
			BaseGestureComboBox.SelectedIndex = 0;
		}

		private void CreateGestureSetButton_Click(object sender, EventArgs e)
		{
			DialogResult = DialogResult.OK;
			Close();
		}

		protected override void OnClosed(EventArgs e)
		{
			if (DialogResult == DialogResult.OK)
			{
				if (AutoCreationRadioButton.Checked)
					m_MainForm.AutoCreateGestureSet(m_Data, m_GestureSet, (int)GesturesToCreateNumericUpDown.Value, BaseGestureComboBox.SelectedIndex - 1, ClearGestureSetCheckBox.Checked);
				else
                    m_MainForm.ManualCreateGestureSet(m_Data, m_GestureSet, (int)GesturesToCreateNumericUpDown.Value, BaseGestureComboBox.SelectedIndex - 1, ClearGestureSetCheckBox.Checked);
			}
		}

		private void AutoCreationRadioButton_CheckedChanged(object sender, EventArgs e)
		{
			if (AutoCreationRadioButton.Checked)
				BaseGestureComboBox.Enabled = true;
			else
			{
				BaseGestureComboBox.Enabled = false;
				BaseGesturePanel.Points = null;
			}
		}

		private void BaseGestureComboBox_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (BaseGestureComboBox.SelectedIndex != -1)
				BaseGesturePanel.Gesture = (BaseGestureComboBox.SelectedIndex == 0) ? m_Data.Gesture : m_GestureSet[BaseGestureComboBox.SelectedIndex - 1];
			else
				BaseGesturePanel.Points = null;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Apex s.r.l.
Italy Italy
I got my Computer Science (Engineering) Master's Degree at the Siena University (Italy), but I'm from Rieti (a small town next to Rome).
My hobbies are RPG, MMORGP, programming and 3D graphics.
At the moment I'm employed at Apex s.r.l. (Modena, Italy) as a senior software developer, working for a WPF/WCF project in Rome.

Comments and Discussions