DataGridViewCell.OnMouseEnter(Int32) DataGridViewCell.OnMouseEnter(Int32) DataGridViewCell.OnMouseEnter(Int32) DataGridViewCell.OnMouseEnter(Int32) Method

定义

当鼠标指针移到单元格上时调用。Called when the mouse pointer moves over a cell.

protected:
 virtual void OnMouseEnter(int rowIndex);
protected virtual void OnMouseEnter (int rowIndex);
abstract member OnMouseEnter : int -> unit
override this.OnMouseEnter : int -> unit
Protected Overridable Sub OnMouseEnter (rowIndex As Integer)

参数

rowIndex
Int32 Int32 Int32 Int32

该单元格的父行索引。The index of the cell's parent row.

示例

下面的代码示例演示如何使用此方法。The following code example illustrates the use of this method. 此示例摘自了如何:通过扩展控件的行为和外观,自定义 Windows 窗体 DataGridView 控件中的单元格和列。This example is part of a larger example available in How to: Customize Cells and Columns in the Windows Forms DataGridView Control by Extending Their Behavior and Appearance.

// Force the cell to repaint itself when the mouse pointer enters it.
protected override void OnMouseEnter(int rowIndex)
{
    this.DataGridView.InvalidateCell(this);
}

// Force the cell to repaint itself when the mouse pointer leaves it.
protected override void OnMouseLeave(int rowIndex)
{
    this.DataGridView.InvalidateCell(this);
}
' Force the cell to repaint itself when the mouse pointer enters it.
Protected Overrides Sub OnMouseEnter(ByVal rowIndex As Integer)
    Me.DataGridView.InvalidateCell(Me)
End Sub

' Force the cell to repaint itself when the mouse pointer leaves it.
Protected Overrides Sub OnMouseLeave(ByVal rowIndex As Integer)
    Me.DataGridView.InvalidateCell(Me)
End Sub

注解

此方法类似DataGridView.OnCellMouseEnter于方法。This method is similar to the DataGridView.OnCellMouseEnter method. 在引发DataGridView.CellMouseEnter事件的相同情况下,它会被调用,但实际上不会引发事件。It is called in the same circumstances in which a DataGridView.CellMouseEnter event is raised, but it does not actually raise the event.

适用于

另请参阅