Mouse action: left, right, middle button and cursor position : Mouse « GUI Windows Form « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Collections Data Structure
3. Components
4. Database ADO.net
5. Development Class
6. Event
7. File Stream
8. GUI Windows Form
9. Language Basics
10. Network
11. Office
12. Regular Expressions
13. Services Event
14. Thread
15. Web Services
16. Windows
17. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C# / C Sharp » GUI Windows Form » MouseScreenshots 
Mouse action: left, right, middle button and cursor position
Mouse action: left, right, middle button and cursor position

  using System;
  using System.Drawing;
  using System.Collections;
  using System.ComponentModel;
  using System.Windows.Forms;
  using System.Data;

  public class MainForm : System.Windows.Forms.Form
  {
    private System.ComponentModel.Container components;

    public MainForm()
    {
      Top = 100;
      Left = 75;
      Height = 100;
      Width = 500;

      MessageBox.Show(Bounds.ToString()"Current rect");

      this.MouseUp += new MouseEventHandler(OnMouseUp);
      this.MouseMove += new MouseEventHandler(OnMouseMove);
      this.KeyUp += new KeyEventHandler(OnKeyUp);
      InitializeComponent();
      CenterToScreen();
    }

    protected override void Disposebool disposing )
    {
      ifdisposing )
      {
        if (components != null
        {
          components.Dispose();
        }
      }
      base.Disposedisposing );
      MessageBox.Show("Disposing this Form");
    }

    private void InitializeComponent()
    {
      this.components = new System.ComponentModel.Container();
      this.Size = new System.Drawing.Size(300,300);
      this.Text = "Form1";
    }

    [STAThread]
    static void Main() 
    {
      Application.Run(new MainForm());
    }
    protected void OnMouseUp(object sender, MouseEventArgs e)
    {
      if(e.Button == MouseButtons.Left)
        MessageBox.Show("Left click!");
      else if(e.Button == MouseButtons.Right)
        MessageBox.Show("Right click!");
      else if(e.Button == MouseButtons.Middle)
        MessageBox.Show("Middle click!");
    }

    protected void OnMouseMove(object sender, MouseEventArgs e)
    {
      this.Text = "Current Pos: (" + e.X + ", " + e.Y + ")";
    }

    public void OnKeyUp(object sender, KeyEventArgs e)
    {
      MessageBox.Show(e.KeyCode.ToString()"Key Pressed!");
    }
  }



           
       
Related examples in the same category
w_w__w._j_av__a___2___s__.___co_m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.