ToolStripItem.OnMouseLeave(EventArgs) 方法
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
引发 MouseLeave 事件。
protected:
virtual void OnMouseLeave(EventArgs ^ e);
C#
protected virtual void OnMouseLeave(EventArgs e);
abstract member OnMouseLeave : EventArgs -> unit
override this.OnMouseLeave : EventArgs -> unit
Protected Overridable Sub OnMouseLeave (e As EventArgs)
下面的代码示例演示如何重写 OnMouseLeave 方法。 此代码示例是为 ToolStripItem 类提供的一个更大示例的一部分。
C#
// This method defines the behavior of the MouseLeave event.
// It sets the state of the rolloverValue field to false and
// tells the control to repaint.
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
this.rolloverValue = false;
this.Invalidate();
}
' This method defines the behavior of the MouseLeave event.
' It sets the state of the rolloverValue field to false and
' tells the control to repaint.
Protected Overrides Sub OnMouseLeave(e As EventArgs)
MyBase.OnMouseLeave(e)
Me.rolloverValue = False
Me.Invalidate()
End Sub
引发事件时,将通过委托调用事件处理程序。 有关详细信息,请参阅 处理和引发事件。
OnMouseLeave 方法还允许派生类对事件进行处理而不必附加委托。 这是在派生类中处理事件的首选技术。
在派生类中重写 OnMouseLeave(EventArgs) 时,一定要调用基类的 OnMouseLeave(EventArgs) 方法,以便已注册的委托对事件进行接收。
产品 | 版本 |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9, 10 |