DataGrid.OnMouseDown(MouseEventArgs) Metoda
Definicja
Ważny
Niektóre informacje dotyczą produktów przedpremierowych, które mogą zostać znacznie zmodyfikowane przed premierą. Microsoft nie udziela żadnych gwarancji, ani wyraźnych, ani domniemanych, dotyczących informacji podanych tutaj.
MouseDown Zgłasza zdarzenie.
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)
Parametry
Element MouseEventArgs zawierający dane o zdarzeniu OnMouseDown(MouseEventArgs) .
Przykłady
Poniższy przykład kodu przedstawia użycie tego elementu członkowskiego.
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
Uwagi
Podnoszenie zdarzenia wywołuje program obsługi zdarzeń przez delegata. Aby zapoznać się z omówieniem, zobacz Obsługa i podnoszenie zdarzeń.
Notatki dla spadkobierców
Podczas zastępowania OnMouseDown(MouseEventArgs) w klasie pochodnej należy wywołać metodę klasy bazowej OnMouseDown(MouseEventArgs) .