DataGrid.OnMouseDown(MouseEventArgs) 方法
本文内容
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
引发 MouseDown 事件。
protected:
override void OnMouseDown(System::Windows::Forms::MouseEventArgs ^ e);
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e);
override this.OnMouseDown : System.Windows.Forms.MouseEventArgs -> unit
Protected Overrides Sub OnMouseDown (e As MouseEventArgs)
一个 MouseEventArgs,它包含有关 OnMouseDown(MouseEventArgs) 事件的数据。
下面的代码示例演示了此成员的用法。
public ref class MyDataGrid: public DataGrid
{
protected:
// Override the OnMouseDown event to select the whole row
// when the user clicks anywhere on a row.
virtual void OnMouseDown( MouseEventArgs^ e ) override
{
// 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);
}
};
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);
}
}
Public Class MyDataGrid
Inherits DataGrid
' Override the OnMouseDown event to select the whole row
' when the user clicks anywhere on a row.
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
' Get the HitTestInfo to return the row and pass
' that value to the IsSelected property of the DataGrid.
Dim hit As DataGrid.HitTestInfo = Me.HitTest(e.X, e.Y)
If hit.Row < 0 Then
Return
End If
If IsSelected(hit.Row) Then
UnSelect(hit.Row)
Else
[Select](hit.Row)
End If
End Sub
End Class
引发事件时,将通过委托调用事件处理程序。 有关概述,请参阅 处理和引发事件。
在派生类中重写 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 |