Csharp/C Sharp/Event/Mouse Event

Материал из .Net Framework эксперт
Версия от 11:34, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Block Mouse

 

using System;
using System.Drawing;
using System.Windows.Forms;
   
class BlockOut: Form
{
     bool      bBlocking, bValidBox;
     Point     ptBeg, ptEnd;
     Rectangle rectBox;
   
     public static void Main()
     {
          Application.Run(new BlockOut());
     }
     protected override void OnMouseDown(MouseEventArgs mea)
     {
          if (mea.Button == MouseButtons.Left)
          {
               ptBeg = ptEnd = new Point(mea.X, mea.Y);
   
               Graphics grfx = CreateGraphics();
               grfx.DrawRectangle(new Pen(ForeColor), Rect(ptBeg, ptEnd));
               grfx.Dispose();
   
               bBlocking = true;
          }
     }
     protected override void OnMouseMove(MouseEventArgs mea)
     {
          if (bBlocking)
          {
               Graphics grfx = CreateGraphics();
               grfx.DrawRectangle(new Pen(BackColor), Rect(ptBeg, ptEnd));
               ptEnd = new Point(mea.X, mea.Y);
               grfx.DrawRectangle(new Pen(ForeColor), Rect(ptBeg, ptEnd));
               grfx.Dispose();
               Invalidate();
          }
     }
     protected override void OnMouseUp(MouseEventArgs mea)
     {
          if (bBlocking && mea.Button == MouseButtons.Left)
          {
               Graphics grfx = CreateGraphics();
               rectBox = Rect(ptBeg, new Point(mea.X, mea.Y));
               grfx.DrawRectangle(new Pen(ForeColor), rectBox);
               grfx.Dispose();
   
               bBlocking = false;
               bValidBox = true;
               Invalidate();
          }
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          Graphics grfx = pea.Graphics;
   
          if (bValidBox)
               grfx.FillRectangle(new SolidBrush(ForeColor), rectBox);
   
          if (bBlocking)
               grfx.DrawRectangle(new Pen(ForeColor), Rect(ptBeg, ptEnd));
     }
     Rectangle Rect(Point ptBeg, Point ptEnd)
     {
          return new Rectangle(Math.Min(ptBeg.X, ptEnd.X),
                               Math.Min(ptBeg.Y, ptEnd.Y),
                               Math.Abs(ptEnd.X - ptBeg.X),
                               Math.Abs(ptEnd.Y - ptBeg.Y));
     }
}


Catch Mouse Click event inside a strange shape

  using System;
  using System.Drawing;
  using System.Drawing.Drawing2D;
  using System.Collections;
  using System.ruponentModel;
  using System.Windows.Forms;
  using System.Data;
  public class Form1 : System.Windows.Forms.Form
  {
    GraphicsPath myPath = new GraphicsPath();
    private bool isImageClicked = false;
    public Form1()
    {
      InitializeComponent();
      myPath.StartFigure();
      myPath.AddLine(new Point(150, 10), new Point(120, 150));
      myPath.AddArc(200, 200, 100, 100, 0, 90);
      Point[] points = {new Point(350, 325), new Point(250, 350), new Point(250, 250), new Point(350, 275)};
      myPath.AddCurve(points);
      myPath.CloseFigure();
      CenterToScreen();
    }
    private void InitializeComponent()
    {
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(292, 273);
      this.Text = "Form1";
      this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
      this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
    }
    static void Main() 
    {
      Application.Run(new Form1());
    }
    private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      Point mousePt = new Point(e.X, e.Y);
            
            if(myPath.IsVisible(mousePt))
      {
        isImageClicked = true;
        this.Text = "You clicked the strange shape...";
      } else {
        isImageClicked = false;
        this.Text = "Images";
      }
      Invalidate();
    }
    private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
      Graphics g = e.Graphics;
      g.FillPath(Brushes.AliceBlue, myPath);
      if(isImageClicked == true)
      {
        Pen outline = new Pen(Color.Black, 2);
                g.DrawPath(outline, myPath);
      }
    }
  }


Full screen and KeyEvent and MouseEvent

// This Article is a simple one to show the usage of KeyEvent and MouseEvent. 
  
// Please move the mouse or press a key to Exit this Program. 
using System; 
using System.Drawing; 
using System.Collections; 
using System.ruponentModel; 
using System.Windows.Forms; 
using System.Data; 
namespace ScreenSave 
{ 
    public class KeyEventandMouseEvent : System.Windows.Forms.Form { 
        private System.Windows.Forms.Label label1; 
        private System.Windows.Forms.Timer timer1; 
        private System.ruponentModel.IContainer components; 
        private Boolean boolFlag; 
        private int ixStart; 
        private int iyStart; 
    
        public KeyEventandMouseEvent() { 
            // 
            // Required for Windows Form Designer support 
            // 
            InitializeComponent(); 
        } 
        /// <summary> 
        /// Clean up any resources being used. 
        /// </summary> 
        protected override void Dispose( bool disposing ) 
        { 
            if( disposing ) { 
                if (components != null) 
                { 
                    components.Dispose(); 
                } 
            } 
            base.Dispose( disposing ); 
        } 
        #region Windows Form Designer generated code 
        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor. 
        /// </summary> 
        private void InitializeComponent() { 
            this.ruponents = new System.ruponentModel.Container(); 
            this.timer1 = new System.Windows.Forms.Timer(this.ruponents); 
            this.label1 = new System.Windows.Forms.Label(); 
            this.SuspendLayout(); 
            // 
            // timer1 
            // 
            this.timer1.Enabled = true; 
            this.timer1.Tick += new System.EventHandler(this.timer1_Tick); 
            // 
            // label1 
            // 
            this.label1.Font = new System.Drawing.Font("Times New Roman", 14F, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); 
            this.label1.ForeColor = System.Drawing.Color.Lime; 
            this.label1.Location = new System.Drawing.Point(8, 280); 
            this.label1.Name = "label1"; 
            this.label1.Size = new System.Drawing.Size(312, 32); 
            this.label1.TabIndex = 0; 
            this.label1.Text = "Roller - Developed in C-Sharp"; 
            this.label1.Click += new System.EventHandler(this.label1_Click); 
            // 
            // KeyEventandMouseEvent 
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); 
            this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64))); 
            this.ClientSize = new System.Drawing.Size(568, 32); 
            this.Controls.AddRange(new System.Windows.Forms.Control[] { 
            this.label1}); 
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 
            this.KeyPreview = true; 
            this.Name = "KeyEventandMouseEvent"; 
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 
            this.Text = "KeyEventandMouseEvent"; 
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized; 
            this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.OnKeyPressEvent); 
            this.Load += new System.EventHandler(this.KeyEventandMouseEvent_Load); 
            this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.OnMouseMoveEvent); 
            this.ResumeLayout(false); 
        } 
        #endregion 
        /// <summary> 
        /// The main entry point for the application. 
        /// </summary> 
        [STAThread] 
        static void Main() 
        { 
            Application.Run(new KeyEventandMouseEvent()); 
        } 
        private void timer1_Tick(object sender, System.EventArgs e) 
        { 
            int i; 
              
            i = label1.Location.X; 
            if (i >= 750) 
            i = 0; 
            else 
            i = label1.Location.X + 5; 
              
            label1.Location = new Point(i,280); 
        } 
        private void KeyEventandMouseEvent_Load(object sender, System.EventArgs e) 
        { 
          
        } 
        private void OnMouseMoveEvent(object sender,MouseEventArgs e) 
        { 
            //Application.Exit(); 
            if (ixStart == 0 && iyStart == 0) 
            { 
                ixStart = e.X; 
                iyStart = e.Y; 
            } 
            else if (e.X != ixStart || e.Y != iyStart) 
                Application.Exit(); 
              
        } 
        private void OnKeyPressEvent(object sender, System.Windows.Forms.KeyPressEventArgs e) 
        { 
            Application.Exit(); 
        } 
        private void label1_Click(object sender, System.EventArgs e) 
        { 
        } 
    } 
}


Handle Mouse click event on an Image

    using System;
  using System.Drawing;
  using System.Drawing.Drawing2D;
  using System.Collections;
  using System.ruponentModel;
  using System.Windows.Forms;
  using System.Data;
  public class Form1 : System.Windows.Forms.Form
  {
    private Image bMapImageA = new Bitmap("winter.jpg");
    private Image bMapImageB = new Bitmap("winter.jpg");
    private Image bMapImageC = new Bitmap("winter.jpg");
    private Rectangle rectA = new Rectangle(10, 10, 90, 90);
    private Rectangle rectB = new Rectangle(10, 110, 90, 90);
    private Rectangle rectC = new Rectangle(10, 210, 90, 90);
    private bool isImageClicked = false;
    private int imageClicked;
    public Form1()
    {
      InitializeComponent();
      CenterToScreen();
    }
    private void InitializeComponent()
    {
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(292, 273);
      this.Text = "Form1";
      this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
      this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
    }
    static void Main() 
    {
      Application.Run(new Form1());
    }
    private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      Point mousePt = new Point(e.X, e.Y);
      if(rectA.Contains(mousePt)) {
        isImageClicked = true;
        imageClicked = 0;
        this.Text = "You clicked image A";
      } else if(rectB.Contains(mousePt)) {
        isImageClicked = true;
        imageClicked = 1;
        this.Text = "You clicked image B";
      } else if(rectC.Contains(mousePt)) {
        isImageClicked = true;
        imageClicked = 2;
        this.Text = "You clicked image C";
      } else {
        isImageClicked = false;
        this.Text = "Images";
      }
      Invalidate();
    }
    private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
      Graphics g = e.Graphics;
      g.DrawImage(bMapImageA, rectA);
      g.DrawImage(bMapImageB, rectB);
      g.DrawImage(bMapImageC, rectC);
      if(isImageClicked == true) {
        Pen outline = new Pen(Color.Black, 2);
        switch(imageClicked) {
          case 0:
            g.DrawRectangle(outline, rectA);
            break;
          case 1:
            g.DrawRectangle(outline, rectB);
            break;
          case 2:
            g.DrawRectangle(outline, rectC);
            break;
          default:
            break;
        }
      }
    }
  }


Hit Testing

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, 
   Zach Greenvoss, Shripad Kulkarni, Neil Whitlow
Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
namespace HitTesting
{
    /// <summary>
    /// Summary description for HitTesting.
    /// </summary>
    public class HitTesting : System.Windows.Forms.Form
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ruponentModel.Container components = null;
        private System.Windows.Forms.Label label1;
        
        GraphicsPath gP;
        string mes = "Move to the big I!";
        FontFamily fF = new FontFamily("Times new roman");
        public HitTesting()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            CreateFont();
            this.Text = "Hit Testing";
            this.label1.Font = new Font(fF, 12);
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(88, 16);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(160, 23);
            this.label1.TabIndex = 0;
            this.label1.Text = "label1";
            // 
            // HitTesting
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(292, 109);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.label1});
            this.Name = "HitTesting";
            this.Text = "HitTesting";
            this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.HitTesting_MouseMove);
            this.ResumeLayout(false);
        }
        #endregion
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new HitTesting());
        }
        void CreateFont()
        {
            Graphics g = this.CreateGraphics();
            label1.Text = mes;
            string s = "I";
            int fSt = (int)FontStyle.Regular;
            Point xy = new Point(50, 10);
            StringFormat sFr = StringFormat.GenericDefault;
 
            gP = new GraphicsPath();  // gp is a class member
            gP.AddString(s, fF, fSt, 50, xy, sFr);  // add the string to the path
        }
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g = this.CreateGraphics();
            g.DrawPath(Pens.Black, gP);  // draw the path to the surface
            g.Dispose();
        }
        private void HitTesting_MouseMove(object sender, MouseEventArgs e)
        {
            Region reg = new Region(gP);
            if(reg.IsVisible(new Point(e.X, e.Y)))
                mes = "You touched me ...";
            else 
                mes = "Move to the big I!";
            CreateFont();
        }
    }
}


Mouse Buttons Click

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, 
   Zach Greenvoss, Shripad Kulkarni, Neil Whitlow
Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
namespace Wrox.WindowGUIProgramming.Chapter5
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class frmMouseButtons : System.Windows.Forms.Form
    {
        private System.Windows.Forms.Label lblLeftClick;
        private System.Windows.Forms.Label lblRightClick;
        private System.Windows.Forms.Label lblMiddleClick;
        private System.Windows.Forms.Label lblHover;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ruponentModel.Container components = null;
        public frmMouseButtons()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            switch(e.Button)
            {
                case(MouseButtons.Left):
                    lblLeftClick.Text = "Left Click";
                    break;
                case(MouseButtons.Middle):
                    lblLeftClick.Text = "Middle Click";
                    break;
                case(MouseButtons.Right):
                    lblLeftClick.Text = "Right Click";
                    break;
                case(MouseButtons.XButton1):
                    lblLeftClick.Text = "XButton1 Click";
                    break;
                case(MouseButtons.XButton2):
                    lblLeftClick.Text = "XButton2 Click";
                    break;
            }
            switch(e.Clicks)
            {
                case 1:
                    lblMiddleClick.Text = "Single Click";
                    break;
                case 2:
                    lblMiddleClick.Text = "Double Click!";
                    break;
                default:
                    lblMiddleClick.Text = "Many clicks!";
                    break;
            }
        }
        protected override void OnMouseWheel(MouseEventArgs e)
        {
            switch(e.Delta)
            {
                case -360:
                    lblRightClick.Text = "One Rotation Reverse";
                    break;
                case -720:
                    lblRightClick.Text = "Two Rotations Reverse";
                    break;
                case 360:
                    lblRightClick.Text = "One Rotation Forward";
                    break;
                case 720:
                    lblRightClick.Text = "Two Rotations Forward";
                    break;
                default:
                    lblRightClick.Text = "Rotation wasn"t full turn of wheel";
                    break;
            }
        }
    
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.lblLeftClick = new System.Windows.Forms.Label();
            this.lblRightClick = new System.Windows.Forms.Label();
            this.lblMiddleClick = new System.Windows.Forms.Label();
            this.lblHover = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // lblLeftClick
            // 
            this.lblLeftClick.Location = new System.Drawing.Point(8, 8);
            this.lblLeftClick.Name = "lblLeftClick";
            this.lblLeftClick.TabIndex = 0;
            // 
            // lblRightClick
            // 
            this.lblRightClick.Location = new System.Drawing.Point(8, 32);
            this.lblRightClick.Name = "lblRightClick";
            this.lblRightClick.Size = new System.Drawing.Size(100, 32);
            this.lblRightClick.TabIndex = 1;
            // 
            // lblMiddleClick
            // 
            this.lblMiddleClick.Location = new System.Drawing.Point(8, 72);
            this.lblMiddleClick.Name = "lblMiddleClick";
            this.lblMiddleClick.TabIndex = 2;
            // 
            // lblHover
            // 
            this.lblHover.Location = new System.Drawing.Point(8, 104);
            this.lblHover.Name = "lblHover";
            this.lblHover.TabIndex = 3;
            this.lblHover.MouseEnter += new System.EventHandler(this.lblHover_MouseEnter);
            this.lblHover.MouseHover += new System.EventHandler(this.lblHover_MouseHover);
            this.lblHover.MouseLeave += new System.EventHandler(this.lblHover_MouseLeave);
            // 
            // frmMouseButtons
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(184, 198);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.lblHover,
                                                                          this.lblMiddleClick,
                                                                          this.lblRightClick,
                                                                          this.lblLeftClick});
            this.MaximizeBox = false;
            this.Name = "frmMouseButtons";
            this.Text = "MouseButtons";
            this.ResumeLayout(false);
        }
        #endregion
        protected void lblHover_MouseEnter(object sender, EventArgs e)
        {
         lblRightClick.Text = "One Rotation Forward";
         lblHover.Text = "Entering label";
            Cursor = Cursors.NoMove2D;
        }
        protected void lblHover_MouseHover(object sender, EventArgs e)
        {
            lblHover.Text = "Hovering over label";
            Cursor = Cursors.Hand;
            System.Diagnostics.Debug.WriteLine("hover");
        }
        protected void lblHover_MouseLeave(object sender, EventArgs e)
        {
            lblHover.Text = "Leaving label";
            Cursor = Cursors.Default;
        }
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new frmMouseButtons());
        }
    }
}


Mouse click action

using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
    private System.Windows.Forms.GroupBox GroupBox1;
    private System.Windows.Forms.Label Label4;
    private System.Windows.Forms.Label Label1;
    private System.Windows.Forms.PictureBox pic;
    private System.Windows.Forms.TextBox txt;
    private System.Windows.Forms.Button cmd;
    private System.Windows.Forms.Label Label2;
    private System.Windows.Forms.Label Label3;
    private System.Windows.Forms.ListBox eventLogList;
    public Form1() {
        InitializeComponent();
    }
    private void Log(String data)
    {
        eventLogList.Items.Add(data);
        int itemsPerPage = (int)(eventLogList.Height / eventLogList.ItemHeight);
        eventLogList.TopIndex = eventLogList.Items.Count - itemsPerPage;
    }
    private void txt_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
        Log("Key Down: " + e.KeyCode.ToString() + e.KeyValue.ToString());
    }
    private void txt_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
        Log("Key Press: " + e.KeyChar.ToString());
    }
    private void txt_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
    {
        Log("Key Up: " + e.KeyCode.ToString() + e.KeyValue.ToString() + " Text is: " + txt.Text);
    }
    private void txt_TextChanged(object sender, System.EventArgs e)
    {
        Log("Changed: " + " Text is: " + txt.Text);
    }
    private void pic_MouseEnter(object sender, System.EventArgs e)
    {
        Log("Mouse Enter");
    }
    private void pic_MouseHover(object sender, System.EventArgs e)
    {
        Log("Mouse Hover");
    }
    private void pic_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        Log("Mouse Down: X=" + e.X.ToString() + " Y=" + e.Y.ToString() + " Button=" + e.Button.ToString());
    }
    private void pic_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        Log("Mouse Up: X=" + e.X.ToString() + " Y=" + e.Y.ToString() + " Button=" + e.Button.ToString());
    }
    private void pic_Click(object sender, System.EventArgs e)
    {
        Log("Click");
    }
    private void pic_DoubleClick(object sender, System.EventArgs e)
    {
        Log("Double Click");
    }
    private void pic_MouseLeave(object sender, System.EventArgs e)
    {
        Log("Mouse Leave");
    }
    private void InitializeComponent()
    {
        this.GroupBox1 = new System.Windows.Forms.GroupBox();
        this.Label4 = new System.Windows.Forms.Label();
        this.Label1 = new System.Windows.Forms.Label();
        this.pic = new System.Windows.Forms.PictureBox();
        this.txt = new System.Windows.Forms.TextBox();
        this.cmd = new System.Windows.Forms.Button();
        this.Label2 = new System.Windows.Forms.Label();
        this.Label3 = new System.Windows.Forms.Label();
        this.eventLogList = new System.Windows.Forms.ListBox();
        this.GroupBox1.SuspendLayout();
        ((System.ruponentModel.ISupportInitialize)(this.pic)).BeginInit();
        this.SuspendLayout();
        // 
        // GroupBox1
        // 
        this.GroupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
        this.GroupBox1.Controls.Add(this.Label4);
        this.GroupBox1.Controls.Add(this.Label1);
        this.GroupBox1.Controls.Add(this.pic);
        this.GroupBox1.Controls.Add(this.txt);
        this.GroupBox1.Controls.Add(this.cmd);
        this.GroupBox1.Controls.Add(this.Label2);
        this.GroupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
        this.GroupBox1.Location = new System.Drawing.Point(7, 0);
        this.GroupBox1.Name = "GroupBox1";
        this.GroupBox1.Size = new System.Drawing.Size(384, 148);
        this.GroupBox1.TabIndex = 12;
        this.GroupBox1.TabStop = false;
        // 
        // Label4
        // 
        this.Label4.Location = new System.Drawing.Point(92, 108);
        this.Label4.Name = "Label4";
        this.Label4.Size = new System.Drawing.Size(56, 16);
        this.Label4.TabIndex = 5;
        this.Label4.Text = "And here:";
        // 
        // Label1
        // 
        this.Label1.Location = new System.Drawing.Point(6, 24);
        this.Label1.Name = "Label1";
        this.Label1.Size = new System.Drawing.Size(144, 16);
        this.Label1.TabIndex = 2;
        this.Label1.Text = "Test keyboard events here:";
        // 
        // pic
        // 
        this.pic.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
        this.pic.Location = new System.Drawing.Point(156, 48);
        this.pic.Name = "pic";
        this.pic.Size = new System.Drawing.Size(192, 48);
        this.pic.TabIndex = 3;
        this.pic.TabStop = false;
        this.pic.DoubleClick += new System.EventHandler(this.pic_DoubleClick);
        this.pic.Click += new System.EventHandler(this.pic_Click);
        this.pic.MouseHover += new System.EventHandler(this.pic_MouseHover);
        this.pic.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_MouseUp);
        this.pic.MouseEnter += new System.EventHandler(this.pic_MouseEnter);
        this.pic.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_MouseDown);
        // 
        // txt
        // 
        this.txt.Location = new System.Drawing.Point(156, 20);
        this.txt.Name = "txt";
        this.txt.Size = new System.Drawing.Size(192, 21);
        this.txt.TabIndex = 1;
        this.txt.KeyUp += new System.Windows.Forms.KeyEventHandler(this.txt_KeyUp);
        this.txt.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_KeyPress);
        this.txt.TextChanged += new System.EventHandler(this.txt_TextChanged);
        this.txt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txt_KeyDown);
        // 
        // cmd
        // 
        this.cmd.FlatStyle = System.Windows.Forms.FlatStyle.System;
        this.cmd.Location = new System.Drawing.Point(156, 100);
        this.cmd.Name = "cmd";
        this.cmd.Size = new System.Drawing.Size(88, 28);
        this.cmd.TabIndex = 4;
        this.cmd.Text = "Button1";
        this.cmd.MouseLeave += new System.EventHandler(this.pic_MouseLeave);
        this.cmd.Click += new System.EventHandler(this.pic_Click);
        this.cmd.MouseEnter += new System.EventHandler(this.pic_MouseEnter);
        this.cmd.MouseHover += new System.EventHandler(this.pic_MouseHover);
        this.cmd.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_MouseUp);
        this.cmd.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_MouseDown);
        // 
        // Label2
        // 
        this.Label2.Location = new System.Drawing.Point(20, 52);
        this.Label2.Name = "Label2";
        this.Label2.Size = new System.Drawing.Size(128, 16);
        this.Label2.TabIndex = 2;
        this.Label2.Text = "Test mouse events here:";
        // 
        // Label3
        // 
        this.Label3.Location = new System.Drawing.Point(23, 100);
        this.Label3.Name = "Label3";
        this.Label3.Size = new System.Drawing.Size(64, 24);
        this.Label3.TabIndex = 11;
        this.Label3.Text = "Label3";
        // 
        // eventLogList
        // 
        this.eventLogList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                    | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
        this.eventLogList.FormattingEnabled = true;
        this.eventLogList.IntegralHeight = false;
        this.eventLogList.Location = new System.Drawing.Point(7, 156);
        this.eventLogList.Name = "eventLogList";
        this.eventLogList.Size = new System.Drawing.Size(384, 212);
        this.eventLogList.TabIndex = 10;
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(399, 374);
        this.Controls.Add(this.GroupBox1);
        this.Controls.Add(this.Label3);
        this.Controls.Add(this.eventLogList);
        this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.Name = "Form1";
        this.Text = "Event Tracker";
        this.GroupBox1.ResumeLayout(false);
        this.GroupBox1.PerformLayout();
        ((System.ruponentModel.ISupportInitialize)(this.pic)).EndInit();
        this.ResumeLayout(false);
    }
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
}


Mouse Double Click event

using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
    private System.Windows.Forms.GroupBox GroupBox1;
    private System.Windows.Forms.Label Label4;
    private System.Windows.Forms.Label Label1;
    private System.Windows.Forms.PictureBox pic;
    private System.Windows.Forms.TextBox txt;
    private System.Windows.Forms.Button cmd;
    private System.Windows.Forms.Label Label2;
    private System.Windows.Forms.Label Label3;
    private System.Windows.Forms.ListBox eventLogList;
    public Form1() {
        InitializeComponent();
    }
    private void Log(String data)
    {
        eventLogList.Items.Add(data);
        int itemsPerPage = (int)(eventLogList.Height / eventLogList.ItemHeight);
        eventLogList.TopIndex = eventLogList.Items.Count - itemsPerPage;
    }
    private void txt_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
        Log("Key Down: " + e.KeyCode.ToString() + e.KeyValue.ToString());
    }
    private void txt_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
        Log("Key Press: " + e.KeyChar.ToString());
    }
    private void txt_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
    {
        Log("Key Up: " + e.KeyCode.ToString() + e.KeyValue.ToString() + " Text is: " + txt.Text);
    }
    private void txt_TextChanged(object sender, System.EventArgs e)
    {
        Log("Changed: " + " Text is: " + txt.Text);
    }
    private void pic_MouseEnter(object sender, System.EventArgs e)
    {
        Log("Mouse Enter");
    }
    private void pic_MouseHover(object sender, System.EventArgs e)
    {
        Log("Mouse Hover");
    }
    private void pic_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        Log("Mouse Down: X=" + e.X.ToString() + " Y=" + e.Y.ToString() + " Button=" + e.Button.ToString());
    }
    private void pic_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        Log("Mouse Up: X=" + e.X.ToString() + " Y=" + e.Y.ToString() + " Button=" + e.Button.ToString());
    }
    private void pic_Click(object sender, System.EventArgs e)
    {
        Log("Click");
    }
    private void pic_DoubleClick(object sender, System.EventArgs e)
    {
        Log("Double Click");
    }
    private void pic_MouseLeave(object sender, System.EventArgs e)
    {
        Log("Mouse Leave");
    }
    private void InitializeComponent()
    {
        this.GroupBox1 = new System.Windows.Forms.GroupBox();
        this.Label4 = new System.Windows.Forms.Label();
        this.Label1 = new System.Windows.Forms.Label();
        this.pic = new System.Windows.Forms.PictureBox();
        this.txt = new System.Windows.Forms.TextBox();
        this.cmd = new System.Windows.Forms.Button();
        this.Label2 = new System.Windows.Forms.Label();
        this.Label3 = new System.Windows.Forms.Label();
        this.eventLogList = new System.Windows.Forms.ListBox();
        this.GroupBox1.SuspendLayout();
        ((System.ruponentModel.ISupportInitialize)(this.pic)).BeginInit();
        this.SuspendLayout();
        // 
        // GroupBox1
        // 
        this.GroupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
        this.GroupBox1.Controls.Add(this.Label4);
        this.GroupBox1.Controls.Add(this.Label1);
        this.GroupBox1.Controls.Add(this.pic);
        this.GroupBox1.Controls.Add(this.txt);
        this.GroupBox1.Controls.Add(this.cmd);
        this.GroupBox1.Controls.Add(this.Label2);
        this.GroupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
        this.GroupBox1.Location = new System.Drawing.Point(7, 0);
        this.GroupBox1.Name = "GroupBox1";
        this.GroupBox1.Size = new System.Drawing.Size(384, 148);
        this.GroupBox1.TabIndex = 12;
        this.GroupBox1.TabStop = false;
        // 
        // Label4
        // 
        this.Label4.Location = new System.Drawing.Point(92, 108);
        this.Label4.Name = "Label4";
        this.Label4.Size = new System.Drawing.Size(56, 16);
        this.Label4.TabIndex = 5;
        this.Label4.Text = "And here:";
        // 
        // Label1
        // 
        this.Label1.Location = new System.Drawing.Point(6, 24);
        this.Label1.Name = "Label1";
        this.Label1.Size = new System.Drawing.Size(144, 16);
        this.Label1.TabIndex = 2;
        this.Label1.Text = "Test keyboard events here:";
        // 
        // pic
        // 
        this.pic.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
        this.pic.Location = new System.Drawing.Point(156, 48);
        this.pic.Name = "pic";
        this.pic.Size = new System.Drawing.Size(192, 48);
        this.pic.TabIndex = 3;
        this.pic.TabStop = false;
        this.pic.DoubleClick += new System.EventHandler(this.pic_DoubleClick);
        this.pic.Click += new System.EventHandler(this.pic_Click);
        this.pic.MouseHover += new System.EventHandler(this.pic_MouseHover);
        this.pic.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_MouseUp);
        this.pic.MouseEnter += new System.EventHandler(this.pic_MouseEnter);
        this.pic.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_MouseDown);
        // 
        // txt
        // 
        this.txt.Location = new System.Drawing.Point(156, 20);
        this.txt.Name = "txt";
        this.txt.Size = new System.Drawing.Size(192, 21);
        this.txt.TabIndex = 1;
        this.txt.KeyUp += new System.Windows.Forms.KeyEventHandler(this.txt_KeyUp);
        this.txt.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_KeyPress);
        this.txt.TextChanged += new System.EventHandler(this.txt_TextChanged);
        this.txt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txt_KeyDown);
        // 
        // cmd
        // 
        this.cmd.FlatStyle = System.Windows.Forms.FlatStyle.System;
        this.cmd.Location = new System.Drawing.Point(156, 100);
        this.cmd.Name = "cmd";
        this.cmd.Size = new System.Drawing.Size(88, 28);
        this.cmd.TabIndex = 4;
        this.cmd.Text = "Button1";
        this.cmd.MouseLeave += new System.EventHandler(this.pic_MouseLeave);
        this.cmd.Click += new System.EventHandler(this.pic_Click);
        this.cmd.MouseEnter += new System.EventHandler(this.pic_MouseEnter);
        this.cmd.MouseHover += new System.EventHandler(this.pic_MouseHover);
        this.cmd.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_MouseUp);
        this.cmd.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_MouseDown);
        // 
        // Label2
        // 
        this.Label2.Location = new System.Drawing.Point(20, 52);
        this.Label2.Name = "Label2";
        this.Label2.Size = new System.Drawing.Size(128, 16);
        this.Label2.TabIndex = 2;
        this.Label2.Text = "Test mouse events here:";
        // 
        // Label3
        // 
        this.Label3.Location = new System.Drawing.Point(23, 100);
        this.Label3.Name = "Label3";
        this.Label3.Size = new System.Drawing.Size(64, 24);
        this.Label3.TabIndex = 11;
        this.Label3.Text = "Label3";
        // 
        // eventLogList
        // 
        this.eventLogList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                    | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
        this.eventLogList.FormattingEnabled = true;
        this.eventLogList.IntegralHeight = false;
        this.eventLogList.Location = new System.Drawing.Point(7, 156);
        this.eventLogList.Name = "eventLogList";
        this.eventLogList.Size = new System.Drawing.Size(384, 212);
        this.eventLogList.TabIndex = 10;
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(399, 374);
        this.Controls.Add(this.GroupBox1);
        this.Controls.Add(this.Label3);
        this.Controls.Add(this.eventLogList);
        this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.Name = "Form1";
        this.Text = "Event Tracker";
        this.GroupBox1.ResumeLayout(false);
        this.GroupBox1.PerformLayout();
        ((System.ruponentModel.ISupportInitialize)(this.pic)).EndInit();
        this.ResumeLayout(false);
    }
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
}


Mouse Down action

using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
    private System.Windows.Forms.GroupBox GroupBox1;
    private System.Windows.Forms.Label Label4;
    private System.Windows.Forms.Label Label1;
    private System.Windows.Forms.PictureBox pic;
    private System.Windows.Forms.TextBox txt;
    private System.Windows.Forms.Button cmd;
    private System.Windows.Forms.Label Label2;
    private System.Windows.Forms.Label Label3;
    private System.Windows.Forms.ListBox eventLogList;
    public Form1() {
        InitializeComponent();
    }
    private void Log(String data)
    {
        eventLogList.Items.Add(data);
        int itemsPerPage = (int)(eventLogList.Height / eventLogList.ItemHeight);
        eventLogList.TopIndex = eventLogList.Items.Count - itemsPerPage;
    }
    private void txt_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
        Log("Key Down: " + e.KeyCode.ToString() + e.KeyValue.ToString());
    }
    private void txt_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
        Log("Key Press: " + e.KeyChar.ToString());
    }
    private void txt_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
    {
        Log("Key Up: " + e.KeyCode.ToString() + e.KeyValue.ToString() + " Text is: " + txt.Text);
    }
    private void txt_TextChanged(object sender, System.EventArgs e)
    {
        Log("Changed: " + " Text is: " + txt.Text);
    }
    private void pic_MouseEnter(object sender, System.EventArgs e)
    {
        Log("Mouse Enter");
    }
    private void pic_MouseHover(object sender, System.EventArgs e)
    {
        Log("Mouse Hover");
    }
    private void pic_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        Log("Mouse Down: X=" + e.X.ToString() + " Y=" + e.Y.ToString() + " Button=" + e.Button.ToString());
    }
    private void pic_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        Log("Mouse Up: X=" + e.X.ToString() + " Y=" + e.Y.ToString() + " Button=" + e.Button.ToString());
    }
    private void pic_Click(object sender, System.EventArgs e)
    {
        Log("Click");
    }
    private void pic_DoubleClick(object sender, System.EventArgs e)
    {
        Log("Double Click");
    }
    private void pic_MouseLeave(object sender, System.EventArgs e)
    {
        Log("Mouse Leave");
    }
    private void InitializeComponent()
    {
        this.GroupBox1 = new System.Windows.Forms.GroupBox();
        this.Label4 = new System.Windows.Forms.Label();
        this.Label1 = new System.Windows.Forms.Label();
        this.pic = new System.Windows.Forms.PictureBox();
        this.txt = new System.Windows.Forms.TextBox();
        this.cmd = new System.Windows.Forms.Button();
        this.Label2 = new System.Windows.Forms.Label();
        this.Label3 = new System.Windows.Forms.Label();
        this.eventLogList = new System.Windows.Forms.ListBox();
        this.GroupBox1.SuspendLayout();
        ((System.ruponentModel.ISupportInitialize)(this.pic)).BeginInit();
        this.SuspendLayout();
        // 
        // GroupBox1
        // 
        this.GroupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
        this.GroupBox1.Controls.Add(this.Label4);
        this.GroupBox1.Controls.Add(this.Label1);
        this.GroupBox1.Controls.Add(this.pic);
        this.GroupBox1.Controls.Add(this.txt);
        this.GroupBox1.Controls.Add(this.cmd);
        this.GroupBox1.Controls.Add(this.Label2);
        this.GroupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
        this.GroupBox1.Location = new System.Drawing.Point(7, 0);
        this.GroupBox1.Name = "GroupBox1";
        this.GroupBox1.Size = new System.Drawing.Size(384, 148);
        this.GroupBox1.TabIndex = 12;
        this.GroupBox1.TabStop = false;
        // 
        // Label4
        // 
        this.Label4.Location = new System.Drawing.Point(92, 108);
        this.Label4.Name = "Label4";
        this.Label4.Size = new System.Drawing.Size(56, 16);
        this.Label4.TabIndex = 5;
        this.Label4.Text = "And here:";
        // 
        // Label1
        // 
        this.Label1.Location = new System.Drawing.Point(6, 24);
        this.Label1.Name = "Label1";
        this.Label1.Size = new System.Drawing.Size(144, 16);
        this.Label1.TabIndex = 2;
        this.Label1.Text = "Test keyboard events here:";
        // 
        // pic
        // 
        this.pic.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
        this.pic.Location = new System.Drawing.Point(156, 48);
        this.pic.Name = "pic";
        this.pic.Size = new System.Drawing.Size(192, 48);
        this.pic.TabIndex = 3;
        this.pic.TabStop = false;
        this.pic.DoubleClick += new System.EventHandler(this.pic_DoubleClick);
        this.pic.Click += new System.EventHandler(this.pic_Click);
        this.pic.MouseHover += new System.EventHandler(this.pic_MouseHover);
        this.pic.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_MouseUp);
        this.pic.MouseEnter += new System.EventHandler(this.pic_MouseEnter);
        this.pic.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_MouseDown);
        // 
        // txt
        // 
        this.txt.Location = new System.Drawing.Point(156, 20);
        this.txt.Name = "txt";
        this.txt.Size = new System.Drawing.Size(192, 21);
        this.txt.TabIndex = 1;
        this.txt.KeyUp += new System.Windows.Forms.KeyEventHandler(this.txt_KeyUp);
        this.txt.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_KeyPress);
        this.txt.TextChanged += new System.EventHandler(this.txt_TextChanged);
        this.txt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txt_KeyDown);
        // 
        // cmd
        // 
        this.cmd.FlatStyle = System.Windows.Forms.FlatStyle.System;
        this.cmd.Location = new System.Drawing.Point(156, 100);
        this.cmd.Name = "cmd";
        this.cmd.Size = new System.Drawing.Size(88, 28);
        this.cmd.TabIndex = 4;
        this.cmd.Text = "Button1";
        this.cmd.MouseLeave += new System.EventHandler(this.pic_MouseLeave);
        this.cmd.Click += new System.EventHandler(this.pic_Click);
        this.cmd.MouseEnter += new System.EventHandler(this.pic_MouseEnter);
        this.cmd.MouseHover += new System.EventHandler(this.pic_MouseHover);
        this.cmd.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_MouseUp);
        this.cmd.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_MouseDown);
        // 
        // Label2
        // 
        this.Label2.Location = new System.Drawing.Point(20, 52);
        this.Label2.Name = "Label2";
        this.Label2.Size = new System.Drawing.Size(128, 16);
        this.Label2.TabIndex = 2;
        this.Label2.Text = "Test mouse events here:";
        // 
        // Label3
        // 
        this.Label3.Location = new System.Drawing.Point(23, 100);
        this.Label3.Name = "Label3";
        this.Label3.Size = new System.Drawing.Size(64, 24);
        this.Label3.TabIndex = 11;
        this.Label3.Text = "Label3";
        // 
        // eventLogList
        // 
        this.eventLogList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                    | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
        this.eventLogList.FormattingEnabled = true;
        this.eventLogList.IntegralHeight = false;
        this.eventLogList.Location = new System.Drawing.Point(7, 156);
        this.eventLogList.Name = "eventLogList";
        this.eventLogList.Size = new System.Drawing.Size(384, 212);
        this.eventLogList.TabIndex = 10;
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(399, 374);
        this.Controls.Add(this.GroupBox1);
        this.Controls.Add(this.Label3);
        this.Controls.Add(this.eventLogList);
        this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.Name = "Form1";
        this.Text = "Event Tracker";
        this.GroupBox1.ResumeLayout(false);
        this.GroupBox1.PerformLayout();
        ((System.ruponentModel.ISupportInitialize)(this.pic)).EndInit();
        this.ResumeLayout(false);
    }
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
}


Mouse Enter action

using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
    private System.Windows.Forms.GroupBox GroupBox1;
    private System.Windows.Forms.Label Label4;
    private System.Windows.Forms.Label Label1;
    private System.Windows.Forms.PictureBox pic;
    private System.Windows.Forms.TextBox txt;
    private System.Windows.Forms.Button cmd;
    private System.Windows.Forms.Label Label2;
    private System.Windows.Forms.Label Label3;
    private System.Windows.Forms.ListBox eventLogList;
    public Form1() {
        InitializeComponent();
    }
    private void Log(String data)
    {
        eventLogList.Items.Add(data);
        int itemsPerPage = (int)(eventLogList.Height / eventLogList.ItemHeight);
        eventLogList.TopIndex = eventLogList.Items.Count - itemsPerPage;
    }
    private void txt_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
        Log("Key Down: " + e.KeyCode.ToString() + e.KeyValue.ToString());
    }
    private void txt_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
        Log("Key Press: " + e.KeyChar.ToString());
    }
    private void txt_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
    {
        Log("Key Up: " + e.KeyCode.ToString() + e.KeyValue.ToString() + " Text is: " + txt.Text);
    }
    private void txt_TextChanged(object sender, System.EventArgs e)
    {
        Log("Changed: " + " Text is: " + txt.Text);
    }
    private void pic_MouseEnter(object sender, System.EventArgs e)
    {
        Log("Mouse Enter");
    }
    private void pic_MouseHover(object sender, System.EventArgs e)
    {
        Log("Mouse Hover");
    }
    private void pic_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        Log("Mouse Down: X=" + e.X.ToString() + " Y=" + e.Y.ToString() + " Button=" + e.Button.ToString());
    }
    private void pic_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        Log("Mouse Up: X=" + e.X.ToString() + " Y=" + e.Y.ToString() + " Button=" + e.Button.ToString());
    }
    private void pic_Click(object sender, System.EventArgs e)
    {
        Log("Click");
    }
    private void pic_DoubleClick(object sender, System.EventArgs e)
    {
        Log("Double Click");
    }
    private void pic_MouseLeave(object sender, System.EventArgs e)
    {
        Log("Mouse Leave");
    }
    private void InitializeComponent()
    {
        this.GroupBox1 = new System.Windows.Forms.GroupBox();
        this.Label4 = new System.Windows.Forms.Label();
        this.Label1 = new System.Windows.Forms.Label();
        this.pic = new System.Windows.Forms.PictureBox();
        this.txt = new System.Windows.Forms.TextBox();
        this.cmd = new System.Windows.Forms.Button();
        this.Label2 = new System.Windows.Forms.Label();
        this.Label3 = new System.Windows.Forms.Label();
        this.eventLogList = new System.Windows.Forms.ListBox();
        this.GroupBox1.SuspendLayout();
        ((System.ruponentModel.ISupportInitialize)(this.pic)).BeginInit();
        this.SuspendLayout();
        // 
        // GroupBox1
        // 
        this.GroupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
        this.GroupBox1.Controls.Add(this.Label4);
        this.GroupBox1.Controls.Add(this.Label1);
        this.GroupBox1.Controls.Add(this.pic);
        this.GroupBox1.Controls.Add(this.txt);
        this.GroupBox1.Controls.Add(this.cmd);
        this.GroupBox1.Controls.Add(this.Label2);
        this.GroupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
        this.GroupBox1.Location = new System.Drawing.Point(7, 0);
        this.GroupBox1.Name = "GroupBox1";
        this.GroupBox1.Size = new System.Drawing.Size(384, 148);
        this.GroupBox1.TabIndex = 12;
        this.GroupBox1.TabStop = false;
        // 
        // Label4
        // 
        this.Label4.Location = new System.Drawing.Point(92, 108);
        this.Label4.Name = "Label4";
        this.Label4.Size = new System.Drawing.Size(56, 16);
        this.Label4.TabIndex = 5;
        this.Label4.Text = "And here:";
        // 
        // Label1
        // 
        this.Label1.Location = new System.Drawing.Point(6, 24);
        this.Label1.Name = "Label1";
        this.Label1.Size = new System.Drawing.Size(144, 16);
        this.Label1.TabIndex = 2;
        this.Label1.Text = "Test keyboard events here:";
        // 
        // pic
        // 
        this.pic.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
        this.pic.Location = new System.Drawing.Point(156, 48);
        this.pic.Name = "pic";
        this.pic.Size = new System.Drawing.Size(192, 48);
        this.pic.TabIndex = 3;
        this.pic.TabStop = false;
        this.pic.DoubleClick += new System.EventHandler(this.pic_DoubleClick);
        this.pic.Click += new System.EventHandler(this.pic_Click);
        this.pic.MouseHover += new System.EventHandler(this.pic_MouseHover);
        this.pic.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_MouseUp);
        this.pic.MouseEnter += new System.EventHandler(this.pic_MouseEnter);
        this.pic.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_MouseDown);
        // 
        // txt
        // 
        this.txt.Location = new System.Drawing.Point(156, 20);
        this.txt.Name = "txt";
        this.txt.Size = new System.Drawing.Size(192, 21);
        this.txt.TabIndex = 1;
        this.txt.KeyUp += new System.Windows.Forms.KeyEventHandler(this.txt_KeyUp);
        this.txt.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_KeyPress);
        this.txt.TextChanged += new System.EventHandler(this.txt_TextChanged);
        this.txt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txt_KeyDown);
        // 
        // cmd
        // 
        this.cmd.FlatStyle = System.Windows.Forms.FlatStyle.System;
        this.cmd.Location = new System.Drawing.Point(156, 100);
        this.cmd.Name = "cmd";
        this.cmd.Size = new System.Drawing.Size(88, 28);
        this.cmd.TabIndex = 4;
        this.cmd.Text = "Button1";
        this.cmd.MouseLeave += new System.EventHandler(this.pic_MouseLeave);
        this.cmd.Click += new System.EventHandler(this.pic_Click);
        this.cmd.MouseEnter += new System.EventHandler(this.pic_MouseEnter);
        this.cmd.MouseHover += new System.EventHandler(this.pic_MouseHover);
        this.cmd.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_MouseUp);
        this.cmd.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_MouseDown);
        // 
        // Label2
        // 
        this.Label2.Location = new System.Drawing.Point(20, 52);
        this.Label2.Name = "Label2";
        this.Label2.Size = new System.Drawing.Size(128, 16);
        this.Label2.TabIndex = 2;
        this.Label2.Text = "Test mouse events here:";
        // 
        // Label3
        // 
        this.Label3.Location = new System.Drawing.Point(23, 100);
        this.Label3.Name = "Label3";
        this.Label3.Size = new System.Drawing.Size(64, 24);
        this.Label3.TabIndex = 11;
        this.Label3.Text = "Label3";
        // 
        // eventLogList
        // 
        this.eventLogList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                    | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
        this.eventLogList.FormattingEnabled = true;
        this.eventLogList.IntegralHeight = false;
        this.eventLogList.Location = new System.Drawing.Point(7, 156);
        this.eventLogList.Name = "eventLogList";
        this.eventLogList.Size = new System.Drawing.Size(384, 212);
        this.eventLogList.TabIndex = 10;
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(399, 374);
        this.Controls.Add(this.GroupBox1);
        this.Controls.Add(this.Label3);
        this.Controls.Add(this.eventLogList);
        this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.Name = "Form1";
        this.Text = "Event Tracker";
        this.GroupBox1.ResumeLayout(false);
        this.GroupBox1.PerformLayout();
        ((System.ruponentModel.ISupportInitialize)(this.pic)).EndInit();
        this.ResumeLayout(false);
    }
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
}


Mouse Exit action

using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
    private System.Windows.Forms.GroupBox GroupBox1;
    private System.Windows.Forms.Label Label4;
    private System.Windows.Forms.Label Label1;
    private System.Windows.Forms.PictureBox pic;
    private System.Windows.Forms.TextBox txt;
    private System.Windows.Forms.Button cmd;
    private System.Windows.Forms.Label Label2;
    private System.Windows.Forms.Label Label3;
    private System.Windows.Forms.ListBox eventLogList;
    public Form1() {
        InitializeComponent();
    }
    private void Log(String data)
    {
        eventLogList.Items.Add(data);
        int itemsPerPage = (int)(eventLogList.Height / eventLogList.ItemHeight);
        eventLogList.TopIndex = eventLogList.Items.Count - itemsPerPage;
    }
    private void txt_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
        Log("Key Down: " + e.KeyCode.ToString() + e.KeyValue.ToString());
    }
    private void txt_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
        Log("Key Press: " + e.KeyChar.ToString());
    }
    private void txt_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
    {
        Log("Key Up: " + e.KeyCode.ToString() + e.KeyValue.ToString() + " Text is: " + txt.Text);
    }
    private void txt_TextChanged(object sender, System.EventArgs e)
    {
        Log("Changed: " + " Text is: " + txt.Text);
    }
    private void pic_MouseEnter(object sender, System.EventArgs e)
    {
        Log("Mouse Enter");
    }
    private void pic_MouseHover(object sender, System.EventArgs e)
    {
        Log("Mouse Hover");
    }
    private void pic_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        Log("Mouse Down: X=" + e.X.ToString() + " Y=" + e.Y.ToString() + " Button=" + e.Button.ToString());
    }
    private void pic_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        Log("Mouse Up: X=" + e.X.ToString() + " Y=" + e.Y.ToString() + " Button=" + e.Button.ToString());
    }
    private void pic_Click(object sender, System.EventArgs e)
    {
        Log("Click");
    }
    private void pic_DoubleClick(object sender, System.EventArgs e)
    {
        Log("Double Click");
    }
    private void pic_MouseLeave(object sender, System.EventArgs e)
    {
        Log("Mouse Leave");
    }
    private void InitializeComponent()
    {
        this.GroupBox1 = new System.Windows.Forms.GroupBox();
        this.Label4 = new System.Windows.Forms.Label();
        this.Label1 = new System.Windows.Forms.Label();
        this.pic = new System.Windows.Forms.PictureBox();
        this.txt = new System.Windows.Forms.TextBox();
        this.cmd = new System.Windows.Forms.Button();
        this.Label2 = new System.Windows.Forms.Label();
        this.Label3 = new System.Windows.Forms.Label();
        this.eventLogList = new System.Windows.Forms.ListBox();
        this.GroupBox1.SuspendLayout();
        ((System.ruponentModel.ISupportInitialize)(this.pic)).BeginInit();
        this.SuspendLayout();
        // 
        // GroupBox1
        // 
        this.GroupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
        this.GroupBox1.Controls.Add(this.Label4);
        this.GroupBox1.Controls.Add(this.Label1);
        this.GroupBox1.Controls.Add(this.pic);
        this.GroupBox1.Controls.Add(this.txt);
        this.GroupBox1.Controls.Add(this.cmd);
        this.GroupBox1.Controls.Add(this.Label2);
        this.GroupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
        this.GroupBox1.Location = new System.Drawing.Point(7, 0);
        this.GroupBox1.Name = "GroupBox1";
        this.GroupBox1.Size = new System.Drawing.Size(384, 148);
        this.GroupBox1.TabIndex = 12;
        this.GroupBox1.TabStop = false;
        // 
        // Label4
        // 
        this.Label4.Location = new System.Drawing.Point(92, 108);
        this.Label4.Name = "Label4";
        this.Label4.Size = new System.Drawing.Size(56, 16);
        this.Label4.TabIndex = 5;
        this.Label4.Text = "And here:";
        // 
        // Label1
        // 
        this.Label1.Location = new System.Drawing.Point(6, 24);
        this.Label1.Name = "Label1";
        this.Label1.Size = new System.Drawing.Size(144, 16);
        this.Label1.TabIndex = 2;
        this.Label1.Text = "Test keyboard events here:";
        // 
        // pic
        // 
        this.pic.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
        this.pic.Location = new System.Drawing.Point(156, 48);
        this.pic.Name = "pic";
        this.pic.Size = new System.Drawing.Size(192, 48);
        this.pic.TabIndex = 3;
        this.pic.TabStop = false;
        this.pic.DoubleClick += new System.EventHandler(this.pic_DoubleClick);
        this.pic.Click += new System.EventHandler(this.pic_Click);
        this.pic.MouseHover += new System.EventHandler(this.pic_MouseHover);
        this.pic.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_MouseUp);
        this.pic.MouseEnter += new System.EventHandler(this.pic_MouseEnter);
        this.pic.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_MouseDown);
        // 
        // txt
        // 
        this.txt.Location = new System.Drawing.Point(156, 20);
        this.txt.Name = "txt";
        this.txt.Size = new System.Drawing.Size(192, 21);
        this.txt.TabIndex = 1;
        this.txt.KeyUp += new System.Windows.Forms.KeyEventHandler(this.txt_KeyUp);
        this.txt.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_KeyPress);
        this.txt.TextChanged += new System.EventHandler(this.txt_TextChanged);
        this.txt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txt_KeyDown);
        // 
        // cmd
        // 
        this.cmd.FlatStyle = System.Windows.Forms.FlatStyle.System;
        this.cmd.Location = new System.Drawing.Point(156, 100);
        this.cmd.Name = "cmd";
        this.cmd.Size = new System.Drawing.Size(88, 28);
        this.cmd.TabIndex = 4;
        this.cmd.Text = "Button1";
        this.cmd.MouseLeave += new System.EventHandler(this.pic_MouseLeave);
        this.cmd.Click += new System.EventHandler(this.pic_Click);
        this.cmd.MouseEnter += new System.EventHandler(this.pic_MouseEnter);
        this.cmd.MouseHover += new System.EventHandler(this.pic_MouseHover);
        this.cmd.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_MouseUp);
        this.cmd.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_MouseDown);
        // 
        // Label2
        // 
        this.Label2.Location = new System.Drawing.Point(20, 52);
        this.Label2.Name = "Label2";
        this.Label2.Size = new System.Drawing.Size(128, 16);
        this.Label2.TabIndex = 2;
        this.Label2.Text = "Test mouse events here:";
        // 
        // Label3
        // 
        this.Label3.Location = new System.Drawing.Point(23, 100);
        this.Label3.Name = "Label3";
        this.Label3.Size = new System.Drawing.Size(64, 24);
        this.Label3.TabIndex = 11;
        this.Label3.Text = "Label3";
        // 
        // eventLogList
        // 
        this.eventLogList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                    | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
        this.eventLogList.FormattingEnabled = true;
        this.eventLogList.IntegralHeight = false;
        this.eventLogList.Location = new System.Drawing.Point(7, 156);
        this.eventLogList.Name = "eventLogList";
        this.eventLogList.Size = new System.Drawing.Size(384, 212);
        this.eventLogList.TabIndex = 10;
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(399, 374);
        this.Controls.Add(this.GroupBox1);
        this.Controls.Add(this.Label3);
        this.Controls.Add(this.eventLogList);
        this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.Name = "Form1";
        this.Text = "Event Tracker";
        this.GroupBox1.ResumeLayout(false);
        this.GroupBox1.PerformLayout();
        ((System.ruponentModel.ISupportInitialize)(this.pic)).EndInit();
        this.ResumeLayout(false);
    }
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
}


Mouse Handler

/*
GDI+ Programming in C# and VB .NET
by Nick Symmonds
Publisher: Apress
ISBN: 159059035X
*/
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
namespace MouseHandler_c
{
    /// <summary>
    /// Summary description for Finally_c.
    /// </summary>
    public class MouseHandler_c : System.Windows.Forms.Form
    {
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Button Off;
        private System.Windows.Forms.Button On;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ruponentModel.Container components = null;
        public MouseHandler_c()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            this.MouseMove += new 
                     System.Windows.Forms.MouseEventHandler(this.MyMouseHandler);
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing ) {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
              this.label1 = new System.Windows.Forms.Label();
              this.Off = new System.Windows.Forms.Button();
              this.On = new System.Windows.Forms.Button();
              this.SuspendLayout();
              // 
              // label1
              // 
              this.label1.Location = new System.Drawing.Point(40, 56);
              this.label1.Name = "label1";
              this.label1.Size = new System.Drawing.Size(176, 16);
              this.label1.TabIndex = 0;
              this.label1.Text = "label1";
              // 
              // Off
              // 
              this.Off.Location = new System.Drawing.Point(40, 216);
              this.Off.Name = "Off";
              this.Off.Size = new System.Drawing.Size(72, 24);
              this.Off.TabIndex = 1;
              this.Off.Text = "Off";
              this.Off.Click += new System.EventHandler(this.Off_Click);
              // 
              // On
              // 
              this.On.Location = new System.Drawing.Point(152, 216);
              this.On.Name = "On";
              this.On.Size = new System.Drawing.Size(72, 24);
              this.On.TabIndex = 2;
              this.On.Text = "On";
              this.On.Click += new System.EventHandler(this.On_Click);
              // 
              // MouseHandler_c
              // 
              this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
              this.ClientSize = new System.Drawing.Size(292, 273);
              this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.On,
                                                                          this.Off,
                                                                          this.label1});
              this.Name = "MouseHandler_c";
              this.Text = "MouseHandler_c";
              this.Load += new System.EventHandler(this.MouseHandler_c_Load);
              this.ResumeLayout(false);
        }
        #endregion
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new MouseHandler_c());
        }
        private void MouseHandler_c_Load(object sender, System.EventArgs e)
        {
        }
        private void MyMouseHandler(object sender, 
                                    System.Windows.Forms.MouseEventArgs e)
        {
          label1.Text = "X= " + e.X.ToString() + ", Y= " + e.Y.ToString();
        }
    
        protected override void OnMouseMove( MouseEventArgs e )
        {
          base.OnMouseMove(e);
        }
    
        private void Off_Click(object sender, System.EventArgs e)
        {
          this.MouseMove -= new 
            System.Windows.Forms.MouseEventHandler(this.MyMouseHandler);
        }
    
        private void On_Click(object sender, System.EventArgs e)
        {
          this.MouseMove += new 
            System.Windows.Forms.MouseEventHandler(this.MyMouseHandler);
        }
    }
}


Mouse Hover action

using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
    private System.Windows.Forms.GroupBox GroupBox1;
    private System.Windows.Forms.Label Label4;
    private System.Windows.Forms.Label Label1;
    private System.Windows.Forms.PictureBox pic;
    private System.Windows.Forms.TextBox txt;
    private System.Windows.Forms.Button cmd;
    private System.Windows.Forms.Label Label2;
    private System.Windows.Forms.Label Label3;
    private System.Windows.Forms.ListBox eventLogList;
    public Form1() {
        InitializeComponent();
    }
    private void Log(String data)
    {
        eventLogList.Items.Add(data);
        int itemsPerPage = (int)(eventLogList.Height / eventLogList.ItemHeight);
        eventLogList.TopIndex = eventLogList.Items.Count - itemsPerPage;
    }
    private void txt_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
        Log("Key Down: " + e.KeyCode.ToString() + e.KeyValue.ToString());
    }
    private void txt_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
        Log("Key Press: " + e.KeyChar.ToString());
    }
    private void txt_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
    {
        Log("Key Up: " + e.KeyCode.ToString() + e.KeyValue.ToString() + " Text is: " + txt.Text);
    }
    private void txt_TextChanged(object sender, System.EventArgs e)
    {
        Log("Changed: " + " Text is: " + txt.Text);
    }
    private void pic_MouseEnter(object sender, System.EventArgs e)
    {
        Log("Mouse Enter");
    }
    private void pic_MouseHover(object sender, System.EventArgs e)
    {
        Log("Mouse Hover");
    }
    private void pic_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        Log("Mouse Down: X=" + e.X.ToString() + " Y=" + e.Y.ToString() + " Button=" + e.Button.ToString());
    }
    private void pic_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        Log("Mouse Up: X=" + e.X.ToString() + " Y=" + e.Y.ToString() + " Button=" + e.Button.ToString());
    }
    private void pic_Click(object sender, System.EventArgs e)
    {
        Log("Click");
    }
    private void pic_DoubleClick(object sender, System.EventArgs e)
    {
        Log("Double Click");
    }
    private void pic_MouseLeave(object sender, System.EventArgs e)
    {
        Log("Mouse Leave");
    }
    private void InitializeComponent()
    {
        this.GroupBox1 = new System.Windows.Forms.GroupBox();
        this.Label4 = new System.Windows.Forms.Label();
        this.Label1 = new System.Windows.Forms.Label();
        this.pic = new System.Windows.Forms.PictureBox();
        this.txt = new System.Windows.Forms.TextBox();
        this.cmd = new System.Windows.Forms.Button();
        this.Label2 = new System.Windows.Forms.Label();
        this.Label3 = new System.Windows.Forms.Label();
        this.eventLogList = new System.Windows.Forms.ListBox();
        this.GroupBox1.SuspendLayout();
        ((System.ruponentModel.ISupportInitialize)(this.pic)).BeginInit();
        this.SuspendLayout();
        // 
        // GroupBox1
        // 
        this.GroupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
        this.GroupBox1.Controls.Add(this.Label4);
        this.GroupBox1.Controls.Add(this.Label1);
        this.GroupBox1.Controls.Add(this.pic);
        this.GroupBox1.Controls.Add(this.txt);
        this.GroupBox1.Controls.Add(this.cmd);
        this.GroupBox1.Controls.Add(this.Label2);
        this.GroupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
        this.GroupBox1.Location = new System.Drawing.Point(7, 0);
        this.GroupBox1.Name = "GroupBox1";
        this.GroupBox1.Size = new System.Drawing.Size(384, 148);
        this.GroupBox1.TabIndex = 12;
        this.GroupBox1.TabStop = false;
        // 
        // Label4
        // 
        this.Label4.Location = new System.Drawing.Point(92, 108);
        this.Label4.Name = "Label4";
        this.Label4.Size = new System.Drawing.Size(56, 16);
        this.Label4.TabIndex = 5;
        this.Label4.Text = "And here:";
        // 
        // Label1
        // 
        this.Label1.Location = new System.Drawing.Point(6, 24);
        this.Label1.Name = "Label1";
        this.Label1.Size = new System.Drawing.Size(144, 16);
        this.Label1.TabIndex = 2;
        this.Label1.Text = "Test keyboard events here:";
        // 
        // pic
        // 
        this.pic.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
        this.pic.Location = new System.Drawing.Point(156, 48);
        this.pic.Name = "pic";
        this.pic.Size = new System.Drawing.Size(192, 48);
        this.pic.TabIndex = 3;
        this.pic.TabStop = false;
        this.pic.DoubleClick += new System.EventHandler(this.pic_DoubleClick);
        this.pic.Click += new System.EventHandler(this.pic_Click);
        this.pic.MouseHover += new System.EventHandler(this.pic_MouseHover);
        this.pic.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_MouseUp);
        this.pic.MouseEnter += new System.EventHandler(this.pic_MouseEnter);
        this.pic.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_MouseDown);
        // 
        // txt
        // 
        this.txt.Location = new System.Drawing.Point(156, 20);
        this.txt.Name = "txt";
        this.txt.Size = new System.Drawing.Size(192, 21);
        this.txt.TabIndex = 1;
        this.txt.KeyUp += new System.Windows.Forms.KeyEventHandler(this.txt_KeyUp);
        this.txt.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_KeyPress);
        this.txt.TextChanged += new System.EventHandler(this.txt_TextChanged);
        this.txt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txt_KeyDown);
        // 
        // cmd
        // 
        this.cmd.FlatStyle = System.Windows.Forms.FlatStyle.System;
        this.cmd.Location = new System.Drawing.Point(156, 100);
        this.cmd.Name = "cmd";
        this.cmd.Size = new System.Drawing.Size(88, 28);
        this.cmd.TabIndex = 4;
        this.cmd.Text = "Button1";
        this.cmd.MouseLeave += new System.EventHandler(this.pic_MouseLeave);
        this.cmd.Click += new System.EventHandler(this.pic_Click);
        this.cmd.MouseEnter += new System.EventHandler(this.pic_MouseEnter);
        this.cmd.MouseHover += new System.EventHandler(this.pic_MouseHover);
        this.cmd.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_MouseUp);
        this.cmd.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_MouseDown);
        // 
        // Label2
        // 
        this.Label2.Location = new System.Drawing.Point(20, 52);
        this.Label2.Name = "Label2";
        this.Label2.Size = new System.Drawing.Size(128, 16);
        this.Label2.TabIndex = 2;
        this.Label2.Text = "Test mouse events here:";
        // 
        // Label3
        // 
        this.Label3.Location = new System.Drawing.Point(23, 100);
        this.Label3.Name = "Label3";
        this.Label3.Size = new System.Drawing.Size(64, 24);
        this.Label3.TabIndex = 11;
        this.Label3.Text = "Label3";
        // 
        // eventLogList
        // 
        this.eventLogList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                    | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
        this.eventLogList.FormattingEnabled = true;
        this.eventLogList.IntegralHeight = false;
        this.eventLogList.Location = new System.Drawing.Point(7, 156);
        this.eventLogList.Name = "eventLogList";
        this.eventLogList.Size = new System.Drawing.Size(384, 212);
        this.eventLogList.TabIndex = 10;
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(399, 374);
        this.Controls.Add(this.GroupBox1);
        this.Controls.Add(this.Label3);
        this.Controls.Add(this.eventLogList);
        this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.Name = "Form1";
        this.Text = "Event Tracker";
        this.GroupBox1.ResumeLayout(false);
        this.GroupBox1.PerformLayout();
        ((System.ruponentModel.ISupportInitialize)(this.pic)).EndInit();
        this.ResumeLayout(false);
    }
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
}


Mouse left click, right click, middle click, hover

 
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class frmMouseButtons : System.Windows.Forms.Form {
    private System.Windows.Forms.Label lblLeftClick;
    private System.Windows.Forms.Label lblRightClick;
    private System.Windows.Forms.Label lblMiddleClick;
    private System.Windows.Forms.Label lblHover;
    public frmMouseButtons() {
        this.lblLeftClick = new System.Windows.Forms.Label();
        this.lblRightClick = new System.Windows.Forms.Label();
        this.lblMiddleClick = new System.Windows.Forms.Label();
        this.lblHover = new System.Windows.Forms.Label();
        this.SuspendLayout();
        this.lblLeftClick.Location = new System.Drawing.Point(8, 8);
        this.lblRightClick.Location = new System.Drawing.Point(8, 32);
        this.lblRightClick.Size = new System.Drawing.Size(100, 32);
        this.lblMiddleClick.Location = new System.Drawing.Point(8, 72);
        this.lblHover.Location = new System.Drawing.Point(8, 104);
        this.lblHover.MouseEnter += new System.EventHandler(this.lblHover_MouseEnter);
        this.lblHover.MouseHover += new System.EventHandler(this.lblHover_MouseHover);
        this.lblHover.MouseLeave += new System.EventHandler(this.lblHover_MouseLeave);
        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
        this.ClientSize = new System.Drawing.Size(184, 198);
        this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.lblHover,
                                      this.lblMiddleClick,
                                      this.lblRightClick,
                                      this.lblLeftClick});
        this.MaximizeBox = false;
        this.ResumeLayout(false);
    }
    protected override void OnMouseDown(MouseEventArgs e) {
        switch (e.Button) {
            case (MouseButtons.Left):
                lblLeftClick.Text = "Left Click";
                break;
            case (MouseButtons.Middle):
                lblLeftClick.Text = "Middle Click";
                break;
            case (MouseButtons.Right):
                lblLeftClick.Text = "Right Click";
                break;
            case (MouseButtons.XButton1):
                lblLeftClick.Text = "XButton1 Click";
                break;
            case (MouseButtons.XButton2):
                lblLeftClick.Text = "XButton2 Click";
                break;
        }
        switch (e.Clicks) {
            case 1:
                lblMiddleClick.Text = "Single Click";
                break;
            case 2:
                lblMiddleClick.Text = "Double Click!";
                break;
            default:
                lblMiddleClick.Text = "Many clicks!";
                break;
        }
    }
    protected override void OnMouseWheel(MouseEventArgs e) {
        switch (e.Delta) {
            case -360:
                lblRightClick.Text = "One Rotation Reverse";
                break;
            case -720:
                lblRightClick.Text = "Two Rotations Reverse";
                break;
            case 360:
                lblRightClick.Text = "One Rotation Forward";
                break;
            case 720:
                lblRightClick.Text = "Two Rotations Forward";
                break;
            default:
                lblRightClick.Text = "Rotation wasn"t full turn of wheel";
                break;
        }
    }

    protected void lblHover_MouseEnter(object sender, EventArgs e) {
        lblRightClick.Text = "One Rotation Forward";
        lblHover.Text = "Entering label";
        Cursor = Cursors.NoMove2D;
    }
    protected void lblHover_MouseHover(object sender, EventArgs e) {
        lblHover.Text = "Hovering over label";
        Cursor = Cursors.Hand;
        System.Diagnostics.Debug.WriteLine("hover");
    }
    protected void lblHover_MouseLeave(object sender, EventArgs e) {
        lblHover.Text = "Leaving label";
        Cursor = Cursors.Default;
    }
    [STAThread]
    static void Main() {
        Application.Run(new frmMouseButtons());
    }
}


Mouse move

/*
GDI+ Programming in C# and VB .NET
by Nick Symmonds
Publisher: Apress
ISBN: 159059035X
*/
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace moveme
{
  public class moveme : System.Windows.Forms.Form
  {
    private const int WM_NCLBUTTONDOWN = 0xA1;
    [DllImport("user32.dll")]
    internal extern static int ReleaseCapture();
    [DllImport("user32.dll")]
    internal extern static int SendMessageA( IntPtr windowHandle, int wMsg, 
                                             int wPAram, int lParam );
    private System.ruponentModel.Container components = null;
    public moveme()
    {
      InitializeComponent();
      this.MouseMove += new MouseEventHandler(this.MyMouseMove);
    }
    protected override void Dispose( bool disposing )
    {
      if( disposing )
      {
        if (components != null) 
        {
          components.Dispose();
        }
      }
      base.Dispose( disposing );
    }
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
      // 
      // moveme
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(292, 273);
      this.Name = "moveme";
      this.Text = "moveme";
      this.Load += new System.EventHandler(this.moveme_Load);
    }
        #endregion
    [STAThread]
    static void Main() 
    {
      Application.Run(new moveme());
    }
    private void moveme_Load(object sender, System.EventArgs e)
    {
    }
    private void MyMouseMove(object sender, MouseEventArgs e)
    {
      if (e.Button==MouseButtons.Left)
      {
        ReleaseCapture();
        SendMessageA( this.Handle, WM_NCLBUTTONDOWN, 2, 0);
      }
    }
    }
}


Mouse Movement

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, 
   Zach Greenvoss, Shripad Kulkarni, Neil Whitlow
Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
namespace Wrox.ProgrammingWindowsGUI.Chapter5
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class MouseMovement : System.Windows.Forms.Form
    {
        private System.Windows.Forms.TextBox txtMouseInfo;
        private System.Windows.Forms.Button btTrackMouseOn;
        private System.Windows.Forms.Button btTrackMouseOff;
        private bool toggleMouse = false;
        private Timer tCheckMouse = new Timer();
        private System.Windows.Forms.Button btScreenTrack;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ruponentModel.Container components = null;
        public MouseMovement()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            txtMouseInfo.Text = GetMouseInfo().ToString();
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
         this.txtMouseInfo = new System.Windows.Forms.TextBox();
         this.btTrackMouseOn = new System.Windows.Forms.Button();
         this.btTrackMouseOff = new System.Windows.Forms.Button();
         this.btScreenTrack = new System.Windows.Forms.Button();
         this.SuspendLayout();
         // 
         // txtMouseInfo
         // 
         this.txtMouseInfo.Multiline = true;
         this.txtMouseInfo.Name = "txtMouseInfo";
         this.txtMouseInfo.ReadOnly = true;
         this.txtMouseInfo.Size = new System.Drawing.Size(432, 320);
         this.txtMouseInfo.TabIndex = 0;
         this.txtMouseInfo.Text = "";
         this.txtMouseInfo.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Control_MouseMove);
         // 
         // btTrackMouseOn
         // 
         this.btTrackMouseOn.Location = new System.Drawing.Point(16, 328);
         this.btTrackMouseOn.Name = "btTrackMouseOn";
         this.btTrackMouseOn.Size = new System.Drawing.Size(192, 23);
         this.btTrackMouseOn.TabIndex = 1;
         this.btTrackMouseOn.Text = "Start Track Mouse";
         this.btTrackMouseOn.Click += new System.EventHandler(this.btTrackMouseOn_Click);
         this.btTrackMouseOn.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Control_MouseMove);
         // 
         // btTrackMouseOff
         // 
         this.btTrackMouseOff.Location = new System.Drawing.Point(232, 328);
         this.btTrackMouseOff.Name = "btTrackMouseOff";
         this.btTrackMouseOff.Size = new System.Drawing.Size(184, 23);
         this.btTrackMouseOff.TabIndex = 2;
         this.btTrackMouseOff.Text = "Stop Track Mouse";
         this.btTrackMouseOff.Click += new System.EventHandler(this.btTrackMouseOff_Click_1);
         this.btTrackMouseOff.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Control_MouseMove);
         // 
         // btScreenTrack
         // 
         this.btScreenTrack.Location = new System.Drawing.Point(16, 360);
         this.btScreenTrack.Name = "btScreenTrack";
         this.btScreenTrack.Size = new System.Drawing.Size(400, 23);
         this.btScreenTrack.TabIndex = 3;
         this.btScreenTrack.Text = "Start Screen wide mouse tracking";
         this.btScreenTrack.Click += new System.EventHandler(this.btScreenTrack_Click);
         // 
         // MouseMovement
         // 
         tCheckMouse.Tick += new EventHandler(Timer_Check);
         tCheckMouse.Enabled = true;
         tCheckMouse.Stop();
         
         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
         this.ClientSize = new System.Drawing.Size(432, 390);
         this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                      this.btScreenTrack,
                                                                      this.btTrackMouseOff,
                                                                      this.btTrackMouseOn,
                                                                      this.txtMouseInfo});
         this.MaximizeBox = false;
         this.Name = "MouseMovement";
         this.Text = "Mouse Movement";
         this.ResumeLayout(false);
      }
        #endregion
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new MouseMovement());
        }
        private StringBuilder GetMouseInfo()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("Mouse Present: "+SystemInformation.MousePresent+"\r\n");
            sb.Append("Number of Mouse Buttons: "+SystemInformation.MouseButtons+"\r\n");
            sb.Append("Mouse Wheel Present: "+SystemInformation.MouseWheelPresent+"\r\n");
            sb.Append("Number of Mouse Wheel scroll lines: "+SystemInformation.MouseWheelScrollLines+"\r\n");
            sb.Append("Native wheel support: "+SystemInformation.NativeMouseWheelSupport+"\r\n");
            sb.Append("Mouse buttons swapped: "+SystemInformation.MouseButtonsSwapped+"\r\n");
            return sb;
        }
        private void btTrackMouseOn_Click(object sender, System.EventArgs e)
        {
            toggleMouse = true;
            tCheckMouse.Stop();
        }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            CheckMousePosition(e, null);
        }
        protected void Control_MouseMove(object sender, MouseEventArgs e)
        {
            CheckMousePosition(e, sender);
        }
        private void CheckMousePosition(MouseEventArgs e, object control)
        {
            if(control==null)
            {
                if(toggleMouse) txtMouseInfo.Text = "x: "+e.X+", y:"+e.Y;
            }
            else
            {
                int left = e.X+((Control)control).Left;
                int top = e.Y+((Control)control).Top;
                if(toggleMouse) txtMouseInfo.Text = "x: "+left+", y:"+top;
            }
        }
        private void btTrackMouseOff_Click(object sender, System.EventArgs e)
        {
            toggleMouse = false;
            txtMouseInfo.Text = GetMouseInfo().ToString();
        }
        private void Timer_Check(object sender, EventArgs e)
        {
         Point pMousePosition = Control.MousePosition;
            txtMouseInfo.Text = "x: "+pMousePosition.X+", y:"+pMousePosition.Y;
        }
        private void btScreenTrack_Click(object sender, System.EventArgs e)
        {
            toggleMouse = false;
            tCheckMouse.Start();
        }
        private void btTrackMouseOff_Click_1(object sender, System.EventArgs e)
        {
            toggleMouse = false;
            txtMouseInfo.Text = GetMouseInfo().ToString();
        }
    }
}


Mouse up action

using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
    private System.Windows.Forms.GroupBox GroupBox1;
    private System.Windows.Forms.Label Label4;
    private System.Windows.Forms.Label Label1;
    private System.Windows.Forms.PictureBox pic;
    private System.Windows.Forms.TextBox txt;
    private System.Windows.Forms.Button cmd;
    private System.Windows.Forms.Label Label2;
    private System.Windows.Forms.Label Label3;
    private System.Windows.Forms.ListBox eventLogList;
    public Form1() {
        InitializeComponent();
    }
    private void Log(String data)
    {
        eventLogList.Items.Add(data);
        int itemsPerPage = (int)(eventLogList.Height / eventLogList.ItemHeight);
        eventLogList.TopIndex = eventLogList.Items.Count - itemsPerPage;
    }
    private void txt_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
        Log("Key Down: " + e.KeyCode.ToString() + e.KeyValue.ToString());
    }
    private void txt_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
        Log("Key Press: " + e.KeyChar.ToString());
    }
    private void txt_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
    {
        Log("Key Up: " + e.KeyCode.ToString() + e.KeyValue.ToString() + " Text is: " + txt.Text);
    }
    private void txt_TextChanged(object sender, System.EventArgs e)
    {
        Log("Changed: " + " Text is: " + txt.Text);
    }
    private void pic_MouseEnter(object sender, System.EventArgs e)
    {
        Log("Mouse Enter");
    }
    private void pic_MouseHover(object sender, System.EventArgs e)
    {
        Log("Mouse Hover");
    }
    private void pic_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        Log("Mouse Down: X=" + e.X.ToString() + " Y=" + e.Y.ToString() + " Button=" + e.Button.ToString());
    }
    private void pic_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        Log("Mouse Up: X=" + e.X.ToString() + " Y=" + e.Y.ToString() + " Button=" + e.Button.ToString());
    }
    private void pic_Click(object sender, System.EventArgs e)
    {
        Log("Click");
    }
    private void pic_DoubleClick(object sender, System.EventArgs e)
    {
        Log("Double Click");
    }
    private void pic_MouseLeave(object sender, System.EventArgs e)
    {
        Log("Mouse Leave");
    }
    private void InitializeComponent()
    {
        this.GroupBox1 = new System.Windows.Forms.GroupBox();
        this.Label4 = new System.Windows.Forms.Label();
        this.Label1 = new System.Windows.Forms.Label();
        this.pic = new System.Windows.Forms.PictureBox();
        this.txt = new System.Windows.Forms.TextBox();
        this.cmd = new System.Windows.Forms.Button();
        this.Label2 = new System.Windows.Forms.Label();
        this.Label3 = new System.Windows.Forms.Label();
        this.eventLogList = new System.Windows.Forms.ListBox();
        this.GroupBox1.SuspendLayout();
        ((System.ruponentModel.ISupportInitialize)(this.pic)).BeginInit();
        this.SuspendLayout();
        // 
        // GroupBox1
        // 
        this.GroupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
        this.GroupBox1.Controls.Add(this.Label4);
        this.GroupBox1.Controls.Add(this.Label1);
        this.GroupBox1.Controls.Add(this.pic);
        this.GroupBox1.Controls.Add(this.txt);
        this.GroupBox1.Controls.Add(this.cmd);
        this.GroupBox1.Controls.Add(this.Label2);
        this.GroupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
        this.GroupBox1.Location = new System.Drawing.Point(7, 0);
        this.GroupBox1.Name = "GroupBox1";
        this.GroupBox1.Size = new System.Drawing.Size(384, 148);
        this.GroupBox1.TabIndex = 12;
        this.GroupBox1.TabStop = false;
        // 
        // Label4
        // 
        this.Label4.Location = new System.Drawing.Point(92, 108);
        this.Label4.Name = "Label4";
        this.Label4.Size = new System.Drawing.Size(56, 16);
        this.Label4.TabIndex = 5;
        this.Label4.Text = "And here:";
        // 
        // Label1
        // 
        this.Label1.Location = new System.Drawing.Point(6, 24);
        this.Label1.Name = "Label1";
        this.Label1.Size = new System.Drawing.Size(144, 16);
        this.Label1.TabIndex = 2;
        this.Label1.Text = "Test keyboard events here:";
        // 
        // pic
        // 
        this.pic.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
        this.pic.Location = new System.Drawing.Point(156, 48);
        this.pic.Name = "pic";
        this.pic.Size = new System.Drawing.Size(192, 48);
        this.pic.TabIndex = 3;
        this.pic.TabStop = false;
        this.pic.DoubleClick += new System.EventHandler(this.pic_DoubleClick);
        this.pic.Click += new System.EventHandler(this.pic_Click);
        this.pic.MouseHover += new System.EventHandler(this.pic_MouseHover);
        this.pic.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_MouseUp);
        this.pic.MouseEnter += new System.EventHandler(this.pic_MouseEnter);
        this.pic.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_MouseDown);
        // 
        // txt
        // 
        this.txt.Location = new System.Drawing.Point(156, 20);
        this.txt.Name = "txt";
        this.txt.Size = new System.Drawing.Size(192, 21);
        this.txt.TabIndex = 1;
        this.txt.KeyUp += new System.Windows.Forms.KeyEventHandler(this.txt_KeyUp);
        this.txt.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_KeyPress);
        this.txt.TextChanged += new System.EventHandler(this.txt_TextChanged);
        this.txt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txt_KeyDown);
        // 
        // cmd
        // 
        this.cmd.FlatStyle = System.Windows.Forms.FlatStyle.System;
        this.cmd.Location = new System.Drawing.Point(156, 100);
        this.cmd.Name = "cmd";
        this.cmd.Size = new System.Drawing.Size(88, 28);
        this.cmd.TabIndex = 4;
        this.cmd.Text = "Button1";
        this.cmd.MouseLeave += new System.EventHandler(this.pic_MouseLeave);
        this.cmd.Click += new System.EventHandler(this.pic_Click);
        this.cmd.MouseEnter += new System.EventHandler(this.pic_MouseEnter);
        this.cmd.MouseHover += new System.EventHandler(this.pic_MouseHover);
        this.cmd.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_MouseUp);
        this.cmd.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_MouseDown);
        // 
        // Label2
        // 
        this.Label2.Location = new System.Drawing.Point(20, 52);
        this.Label2.Name = "Label2";
        this.Label2.Size = new System.Drawing.Size(128, 16);
        this.Label2.TabIndex = 2;
        this.Label2.Text = "Test mouse events here:";
        // 
        // Label3
        // 
        this.Label3.Location = new System.Drawing.Point(23, 100);
        this.Label3.Name = "Label3";
        this.Label3.Size = new System.Drawing.Size(64, 24);
        this.Label3.TabIndex = 11;
        this.Label3.Text = "Label3";
        // 
        // eventLogList
        // 
        this.eventLogList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                    | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
        this.eventLogList.FormattingEnabled = true;
        this.eventLogList.IntegralHeight = false;
        this.eventLogList.Location = new System.Drawing.Point(7, 156);
        this.eventLogList.Name = "eventLogList";
        this.eventLogList.Size = new System.Drawing.Size(384, 212);
        this.eventLogList.TabIndex = 10;
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(399, 374);
        this.Controls.Add(this.GroupBox1);
        this.Controls.Add(this.Label3);
        this.Controls.Add(this.eventLogList);
        this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.Name = "Form1";
        this.Text = "Event Tracker";
        this.GroupBox1.ResumeLayout(false);
        this.GroupBox1.PerformLayout();
        ((System.ruponentModel.ISupportInitialize)(this.pic)).EndInit();
        this.ResumeLayout(false);
    }
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
}


Register Form Mouse Move, down and up action

using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
   bool shouldPaint = false;
   public Form1() {
       InitializeComponent();
   }
   private void PainterForm_MouseDown( object sender, MouseEventArgs e )
   {
      shouldPaint = true;
   }
   private void PainterForm_MouseUp( object sender, MouseEventArgs e )
   {
      shouldPaint = false;
   }
   private void PainterForm_MouseMove( object sender, MouseEventArgs e )
   {
      if ( shouldPaint )
      {
         Graphics graphics = CreateGraphics();
         graphics.FillEllipse(new SolidBrush( Color.BlueViolet ), e.X, e.Y, 4, 4 );
         graphics.Dispose();
      }
   }
  private void InitializeComponent()
  {
     this.SuspendLayout();
     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     this.ClientSize = new System.Drawing.Size(184, 180);
     this.Name = "PainterForm";
     this.Text = "Painter";
     this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PainterForm_MouseDown);
     this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PainterForm_MouseUp);
     this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PainterForm_MouseMove);
     this.ResumeLayout(false);
  }
  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }
}


Which mouse button was clicked?

 
using System;
using System.Windows.Forms;
using System.Drawing;
public class MainWindow : Form {
    public MainWindow() {
        Height = 300;
        Width = 500;
        this.MouseMove += new MouseEventHandler(MainForm_MouseMove);
        this.MouseUp += new MouseEventHandler(MainForm_MouseUp);
        this.KeyUp += new KeyEventHandler(MainForm_KeyUp);
    }
    protected void MainForm_MouseMove(object sender, MouseEventArgs e) {
        this.Text = string.Format("Current Pos: ({0}, {1})", e.X, e.Y);
    }
    protected void MainForm_MouseUp(object sender, MouseEventArgs e) {
        if (e.Button == MouseButtons.Left)
            MessageBox.Show("Left click!");
        if (e.Button == MouseButtons.Right)
            MessageBox.Show("Right click!");
        if (e.Button == MouseButtons.Middle)
            MessageBox.Show("Middle click!");
    }
    protected void MainForm_KeyUp(object sender, KeyEventArgs e) {
        MessageBox.Show(e.KeyCode.ToString(), "Key Pressed!");
    }
    public static void Main(string[] args) {
        Application.Run(new MainWindow());
    }
}