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) 方法。