DataGrid.OnMouseDown 方法
引发 MouseDown 事件。
**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)
语法
声明
Protected Overrides Sub OnMouseDown ( _
e As MouseEventArgs _
)
用法
Dim e As MouseEventArgs
Me.OnMouseDown(e)
protected override void OnMouseDown (
MouseEventArgs e
)
protected:
virtual void OnMouseDown (
MouseEventArgs^ e
) override
protected void OnMouseDown (
MouseEventArgs e
)
protected override function OnMouseDown (
e : MouseEventArgs
)
参数
- e
一个 MouseEventArgs,它包含有关 OnMouseDown 事件的数据。
备注
引发事件时会通过委托调用事件处理程序。有关概述,请参见 引发事件。
给继承者的说明 重写派生类中的 OnMouseDown 时,确保调用基类的 OnMouseDown 方法。
示例
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
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 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 extends DataGrid
{
// Override the OnMouseDown event to select the whole row
// when the user clicks anywhere on a row.
protected 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.get_X(), e.get_Y());
if (hit.get_Row() < 0) {
return;
}
if (this.IsSelected(hit.get_Row())) {
UnSelect(hit.get_Row());
}
else {
Select(hit.get_Row());
}
} //OnMouseDown
} //MyDataGrid
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0