ToolStripItem.OnMouseEnter(EventArgs) 方法

定义

引发 MouseEnter 事件。

protected:
 virtual void OnMouseEnter(EventArgs ^ e);
protected virtual void OnMouseEnter(EventArgs e);
abstract member OnMouseEnter : EventArgs -> unit
override this.OnMouseEnter : EventArgs -> unit
Protected Overridable Sub OnMouseEnter (e As EventArgs)

参数

e
EventArgs

包含事件数据的一个 EventArgs

示例

下面的代码示例演示如何重写 OnMouseEnter 方法。 该代码示例是 ToolStripItem 类中的一个较大示例的一部分。

// This method defines the behavior of the MouseEnter event.
// It sets the state of the rolloverValue field to true and
// tells the control to repaint.
protected override void OnMouseEnter(EventArgs e)
{
    base.OnMouseEnter(e);

    this.rolloverValue = true;

    this.Invalidate();
}
' This method defines the behavior of the MouseEnter event.
' It sets the state of the rolloverValue field to true and
' tells the control to repaint.
Protected Overrides Sub OnMouseEnter(e As EventArgs)
   MyBase.OnMouseEnter(e)
   
   Me.rolloverValue = True
   
   Me.Invalidate()
 End Sub

注解

引发事件会通过委托调用事件处理程序。 有关详细信息,请参阅 处理和引发事件

该方法 OnMouseEnter 还允许派生类在不附加委托的情况下处理事件。 这是处理派生类中的事件的首选技术。

继承者说明

在派生类中重写 OnMouseEnter(EventArgs) 时,请务必调用基类的方法,以便已注册的 OnMouseEnter(EventArgs) 委托接收事件。

适用于