MouseEventArgs 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
public ref class MouseEventArgs : EventArgs
	[System.Runtime.InteropServices.ComVisible(true)]
public class MouseEventArgs : EventArgs
	public class MouseEventArgs : EventArgs
	[<System.Runtime.InteropServices.ComVisible(true)>]
type MouseEventArgs = class
    inherit EventArgs
	type MouseEventArgs = class
    inherit EventArgs
	Public Class MouseEventArgs
Inherits EventArgs
		- 继承
 
- 派生
 
- 属性
 
示例
下面的代码示例处理 MouseDown 控件上的 TextBox 事件,以便单击鼠标右键选择控件中的所有文本。 此示例要求具有包含名为 的textBox1控件的窗体TextBox。
private void Form1_Load(object sender, EventArgs e)
{
    // This line suppresses the default context menu for the TextBox control. 
    textBox1.ContextMenu = new ContextMenu();
    textBox1.MouseDown += new MouseEventHandler(textBox1_MouseDown);
}
void textBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        textBox1.Select(0, textBox1.Text.Length);
    }
}
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    TextBox1.ContextMenuStrip = New ContextMenuStrip()
End Sub
Private Sub TextBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown
    If (e.Button = MouseButtons.Right) Then
        TextBox1.Select(0, TextBox1.Text.Length)
    End If
End Sub
下面的代码示例使用 Location 属性跟踪鼠标左键的单击次数,并绘制一系列直线段以响应用户输入。 如果隐藏窗体,然后重新显示窗体,则本示例不会重新绘制线条;为简单起见,省略了此代码。
Point firstPoint;
Boolean haveFirstPoint;
public void EnableDrawing()
{
    this.MouseDown += new MouseEventHandler(Form1_MouseDownDrawing);
}
void Form1_MouseDownDrawing(object sender, System.Windows.Forms.MouseEventArgs e)
{
    if (haveFirstPoint)
    {
        Graphics g = this.CreateGraphics();
        g.DrawLine(Pens.Black, firstPoint, e.Location);
        haveFirstPoint = false;
    }
    else
    {
        firstPoint = e.Location;
        haveFirstPoint = true;
    }
}
Dim FirstPoint As Point
Dim HaveFirstPoint As Boolean = False
Private Sub Form1_MouseDownDrawing(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
    If HaveFirstPoint Then
        Dim g As Graphics = Me.CreateGraphics()
        g.DrawLine(Pens.Black, FirstPoint, e.Location)
        HaveFirstPoint = False
    Else
        FirstPoint = e.Location
        HaveFirstPoint = True
    End If
End Sub
下面的代码示例使用 X 和 Y 属性显示鼠标指针在 ToolTip 窗口中的当前位置。
ToolTip trackTip;
private void TrackCoordinates()
{
    trackTip = new ToolTip();
    this.MouseMove += new MouseEventHandler(Form1_MouseMove);
}
void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
    String tipText = String.Format("({0}, {1})", e.X, e.Y);
    trackTip.Show(tipText, this, e.Location);
}
Dim TrackTip As ToolTip
Private Sub TrackCoordinates()
    TrackTip = New ToolTip()
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
    Dim TipText As String = String.Format("({0}, {1})", e.X, e.Y)
    TrackTip.Show(TipText, Me, e.Location)
End Sub
	注解
当用户 MouseDown 在指针位于控件上时按下鼠标按钮时,将发生该事件。 当用户 MouseUp 松开鼠标按钮,而指针停留在控件上时,将发生该事件。 MouseMove当用户将鼠标指针移到控件上时发生 该事件。 指定 MouseEventArgs 按下的鼠标按钮、按下和释放鼠标按钮的次数、鼠标坐标以及鼠标滚轮的移动量。
如果用户在松开鼠标按钮之前将焦点切换到另一个 MouseDown 应用程序,则可能会收到没有相应 MouseUp的事件。
、 和 NotifyIcon 类存在ControlAxHost这三个事件。
有关事件模型的信息,请参阅 处理和引发事件。
构造函数
| MouseEventArgs(MouseButtons, Int32, Int32, Int32, Int32) | 
		 初始化 MouseEventArgs 类的新实例。  | 
        	
属性
| Button | 
		 获取曾按下的是哪个鼠标按钮。  | 
        	
| Clicks | 
		 获取按下并释放鼠标按钮的次数。  | 
        	
| Delta | 
		 获取鼠标轮已转动的制动器数的有符号计数乘以 WHEEL_DELTA 常数。 制动器是鼠标轮的一个凹口。  | 
        	
| Location | 
		 获取鼠标在产生鼠标事件时的位置。  | 
        	
| X | 
		 获取鼠标在产生鼠标事件时的 x 坐标。  | 
        	
| Y | 
		 获取鼠标在产生鼠标事件时的 y 坐标。  | 
        	
方法
| Equals(Object) | 
		 确定指定对象是否等于当前对象。 (继承自 Object) | 
        	
| GetHashCode() | 
		 作为默认哈希函数。 (继承自 Object) | 
        	
| GetType() | 
		 获取当前实例的 Type。 (继承自 Object) | 
        	
| MemberwiseClone() | 
		 创建当前 Object 的浅表副本。 (继承自 Object) | 
        	
| ToString() | 
		 返回表示当前对象的字符串。 (继承自 Object) |