//获取鼠标的位置和鼠标的事件
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
public class Form1 : Form
{
private System.ComponentModel.Container components = null;
public Form1 ()
{
InitializeComponent ();
}
protected override void Dispose (bool disposing )
{
if (disposing )
{
if (components != null)
{
components.Dispose ();
}
}
base.Dispose (disposing );
}
private void InitializeComponent ()
{
this.AutoScaleBaseSize = new System.Drawing.Size (6 , 14);
this.ClientSize = new System.Drawing.Size (292 , 273 );
this.Name = "Form1";
this.Text = "C#处理鼠标按动事件!";
this.MouseDown += new MouseEventHandler (Form1_MouseDown );
this.MouseMove += new MouseEventHandler (Form1_OnMouseMove );
}
static void Main ()
{
Application.Run (new Form1 () );
}
private void Form1_OnMouseMove (object sender , MouseEventArgs e )
{
this.Text = "当前鼠标的位置为:(" + e.X + " , " + e.Y + ")";
}
private void Form1_MouseDown (object sender , MouseEventArgs e )
{
if (e.Button == MouseButtons.Left )
{
MessageBox.Show ("按动鼠标左键!" );
}
if (e.Button == MouseButtons.Middle )
{
MessageBox.Show ("按动鼠标中键!");
}
if (e.Button == MouseButtons.Right )
{
MessageBox.Show ("按动鼠标右键!");
}
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
public class Form1 : Form
{
private System.ComponentModel.Container components = null;
public Form1 ()
{
InitializeComponent ();
}
protected override void Dispose (bool disposing )
{
if (disposing )
{
if (components != null)
{
components.Dispose ();
}
}
base.Dispose (disposing );
}
private void InitializeComponent ()
{
this.AutoScaleBaseSize = new System.Drawing.Size (6 , 14);
this.ClientSize = new System.Drawing.Size (292 , 273 );
this.Name = "Form1";
this.Text = "C#处理鼠标按动事件!";
this.MouseDown += new MouseEventHandler (Form1_MouseDown );
this.MouseMove += new MouseEventHandler (Form1_OnMouseMove );
}
static void Main ()
{
Application.Run (new Form1 () );
}
private void Form1_OnMouseMove (object sender , MouseEventArgs e )
{
this.Text = "当前鼠标的位置为:(" + e.X + " , " + e.Y + ")";
}
private void Form1_MouseDown (object sender , MouseEventArgs e )
{
if (e.Button == MouseButtons.Left )
{
MessageBox.Show ("按动鼠标左键!" );
}
if (e.Button == MouseButtons.Middle )
{
MessageBox.Show ("按动鼠标中键!");
}
if (e.Button == MouseButtons.Right )
{
MessageBox.Show ("按动鼠标右键!");
}
}
}