DataGrid.OnMouseDown(MouseEventArgs) 方法

定义

引发 MouseDown 事件。

protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e);

参数

e
MouseEventArgs

一个 MouseEventArgs,它包含有关 OnMouseDown(MouseEventArgs) 事件的数据。

示例

下面的代码示例演示了此成员的用法。

public class MyDataGrid : DataGrid 
{
    // Override the OnMouseDown event to select the whole row
    // when the user clicks anywhere on a row.
    protected override void OnMouseDown(MouseEventArgs e) 
    {
        // Get the HitTestInfo to return the row and pass
        // that value to the IsSelected property of the DataGrid.
        DataGrid.HitTestInfo hit = this.HitTest(e.X, e.Y);
        if (hit.Row < 0)
            return;
        if (this.IsSelected(hit.Row))
            UnSelect(hit.Row);
        else
            Select(hit.Row);
    }
}

注解

引发事件时,将通过委托调用事件处理程序。 有关概述,请参阅 处理和引发事件

继承者说明

在派生类中重写 OnMouseDown(MouseEventArgs) 时,请务必调用基类的 OnMouseDown(MouseEventArgs) 方法。

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0