Control.OnMouseHover 方法
引发 MouseHover 事件。
**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)
语法
声明
Protected Overridable Sub OnMouseHover ( _
e As EventArgs _
)
用法
Dim e As EventArgs
Me.OnMouseHover(e)
protected virtual void OnMouseHover (
EventArgs e
)
protected:
virtual void OnMouseHover (
EventArgs^ e
)
protected void OnMouseHover (
EventArgs e
)
protected function OnMouseHover (
e : EventArgs
)
参数
- e
包含事件数据的 EventArgs。
备注
引发事件时会通过委托调用事件处理程序。有关更多信息,请参见 引发事件。
OnMouseHover 方法还允许派生类对事件进行处理而不必附加委托。这是在派生类中处理事件的首选技术。
给继承者的说明 在派生类中重写 OnMouseHover 时,一定要调用基类的 OnMouseHover 方法,以便已注册的委托对事件进行接收。
示例
下面的代码示例演示如何重写派生类中的 OnMouseHover 和 OnMouseMove 方法。要运行该示例,请将以下代码粘贴到一个新窗体中并将该类粘贴到此窗体的后面,以构成同一个文件。将一个 FunButton 类型的按钮添加到窗体中。
Public Class FunButton
Inherits Button
Protected Overrides Sub OnMouseHover(ByVal e As System.EventArgs)
' Get the font size in Points, add one to the
' size, and reset the button's font to the larger
' size.
Dim fontSize As Single = Font.SizeInPoints
fontSize += 1
Dim buttonSize As System.Drawing.Size = Size
Me.Font = New System.Drawing.Font _
(Font.FontFamily, fontSize, Font.Style)
' Increase the size width and height of the button
' by 5 points each.
Size = New System.Drawing.Size _
(Size.Width + 5, Size.Height + 5)
' Call myBase.OnMouseHover to activate the delegate.
MyBase.OnMouseHover(e)
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
' Make the curser the Hand curser when the mouse moves
' over the button.
Cursor = Cursors.Hand
' Call MyBase.OnMouseHover to activate the delegate.
MyBase.OnMouseHover(e)
End Sub
public class FunButton:
Button
{
protected override void OnMouseHover(System.EventArgs e)
{
// Get the font size in Points, add one to the
// size, and reset the button's font to the larger
// size.
float fontSize = Font.SizeInPoints;
fontSize += 1;
System.Drawing.Size buttonSize = Size;
this.Font = new System.Drawing.Font(
Font.FontFamily, fontSize, Font.Style);
// Increase the size width and height of the button
// by 5 points each.
Size = new System.Drawing.Size(Size.Width+5, Size.Height+5);
// Call myBase.OnMouseHover to activate the delegate.
base.OnMouseHover(e);
}
protected override void OnMouseMove(MouseEventArgs e)
{
// Make the curser the Hand curser when the mouse moves
// over the button.
Cursor = Cursors.Hand;
// Call MyBase.OnMouseHover to activate the delegate.
base.OnMouseHover(e);
}
// To use this example create a new form and paste this class
// forming the same file, after the form class in the same file.
// Add a button of type FunButton to the form.
public ref class FunButton: public Button
{
protected:
virtual void OnMouseHover( System::EventArgs^ e ) override
{
// Get the font size in Points, add one to the
// size, and reset the button's font to the larger
// size.
float fontSize = Font->SizeInPoints;
fontSize += 1;
System::Drawing::Size buttonSize = Size;
this->Font = gcnew System::Drawing::Font( Font->FontFamily,fontSize,Font->Style );
// Increase the size width and height of the button
// by 5 points each.
Size = System::Drawing::Size( Size.Width + 5, Size.Height + 5 );
// Call myBase.OnMouseHover to activate the delegate.
Button::OnMouseHover( e );
}
virtual void OnMouseMove( MouseEventArgs^ e ) override
{
// Make the curser the Hand curser when the mouse moves
// over the button.
Cursor = Cursors::Hand;
// Call MyBase.OnMouseHover to activate the delegate.
Button::OnMouseHover( e );
}
public class FunButton extends Button
{
protected void OnMouseHover(System.EventArgs e)
{
// Get the font size in Points, add one to the
// size, and reset the button's font to the larger
// size.
float fontSize = get_Font().get_SizeInPoints();
fontSize += 1;
System.Drawing.Size buttonSize = get_Size();
this.set_Font(new System.Drawing.Font(get_Font().get_FontFamily(),
fontSize, get_Font().get_Style()));
// Increase the size width and height of the button
// by 5 points each.
set_Size(new System.Drawing.Size(get_Size().get_Width() + 5,
get_Size().get_Height() + 5));
// Call myBase.OnMouseHover to activate the delegate.
super.OnMouseHover(e);
} //OnMouseHover
protected void OnMouseMove(MouseEventArgs e)
{
// Make the curser the Hand curser when the mouse moves
// over the button.
set_Cursor(Cursors.get_Hand());
// Call MyBase.OnMouseHover to activate the delegate.
super.OnMouseHover(e);
} //OnMouseMove
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
Control 类
Control 成员
System.Windows.Forms 命名空间
MouseHover
MouseEventArgs