Click here to Skip to main content
15,896,606 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 222.1K   8.1K   144  
This program can create and recognize mouse gestures.
using System;
using System.Drawing;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;

namespace GestureRecognizer
{
	public enum MessageType
	{
		Error,
		Normal,
		Info
	}

	public class TransparentLabel : System.Windows.Forms.Label
	{
		private Color m_BaseColor;
		private int m_Transparency;
		private Color m_StandardColor;
		private Color m_InfoColor;
		private Color m_ErrorColor;

		public Color BaseColor { get { return m_BaseColor; } set { m_BaseColor = value; BackColor = Color.FromArgb(m_Transparency, value); Refresh(); } }
		public int Transparency { get { return m_Transparency; } set { m_Transparency = value; BackColor = Color.FromArgb(value, m_BaseColor); Refresh(); } }
		public Color StandardColor { get { return m_StandardColor; } set { m_StandardColor = value; Refresh(); } }
		public Color InfoColor { get { return m_InfoColor; } set { m_InfoColor = value; Refresh(); } }
		public Color ErrorColor { get { return m_ErrorColor; } set { m_ErrorColor = value; Refresh(); } }

		public TransparentLabel()
		{
			SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
			DoubleBuffered = true;

			m_StandardColor = Color.Gray;
			m_InfoColor = Color.Blue;
			m_ErrorColor = Color.Red;
			ForeColor = m_InfoColor;
			m_BaseColor = Color.Gray;
			m_Transparency = 50;
			BackColor = Color.FromArgb(m_Transparency, m_BaseColor);
		}

		protected override void OnPaint(PaintEventArgs e)
		{
			base.OnPaint(e);
			e.Graphics.DrawRectangle(new Pen(BaseColor), 0, 0, Width - 1, Height - 1);
		}

		public void ShowMessage(string str, MessageType type)
		{
			Text = str;

			#region Linking MessageType to Color
			switch (type)
			{
				case MessageType.Normal:
					{
						ForeColor = m_StandardColor;
						break;
					}
				case MessageType.Info:
					{
						ForeColor = m_InfoColor;
						break;
					}
				case MessageType.Error:
					{
						ForeColor = m_ErrorColor;
						break;
					}
			}
			#endregion

			Refresh();
			//Invalidate();
		}

		public void ShowMessage(string str)
		{
			Text = str;

			Refresh();
			//Invalidate();
		}

		public void ShowMessage(string[] strs, MessageType type)
		{
			string text = "";

			for (int i = 0; i < strs.Length; i++)
				text += strs[i] + (i == strs.Length - 1 ? "" : "\n");

			ShowMessage(text, type);
		}

		public void ShowMessage(string[] strs)
		{
			string text = "";

			for (int i = 0; i < strs.Length; i++)
				text += strs[i] + (i == strs.Length - 1 ? "" : "\n");

			ShowMessage(text);
		}
	}
}

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