다음을 통해 공유


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 메서드를 호출해야 합니다.

예제

다음 코드 예제에서는 파생 클래스의 OnMouseHoverOnMouseMove 메서드를 재정의하는 방법을 보여 줍니다. 이 예제를 실행하려면 새 폼에 다음 코드를 붙여넣고 이 클래스를 붙여넣어 해당 폼 다음에 동일한 파일을 만듭니다. 그런 다음 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

기타 리소스

Windows Forms 좌표
Windows Forms의 마우스 이벤트