Control.OnMouseHover(EventArgs) 메서드

정의

MouseHover 이벤트를 발생시킵니다.

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

매개 변수

e
EventArgs

이벤트 데이터가 포함된 EventArgs입니다.

예제

다음 코드 예제에서는 재정의 OnMouseHover 하는 방법에 설명 합니다 및 OnMouseMove 파생된 클래스의 메서드입니다. 예제를 실행, 새 폼에 다음 코드를 붙여 붙여넣습니다이 클래스를 같은 파일 형식을 만듭니다. 형식 FunButton 의 단추를 양식에 추가합니다.

// 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 cursor the Hand cursor when the mouse moves 
      // over the button.
      Cursor = Cursors::Hand;
      
      // Call MyBase.OnMouseMove to activate the delegate.
      Button::OnMouseMove( e );
   }
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 cursor the Hand cursor when the mouse moves 
        // over the button.
        Cursor = Cursors.Hand;

        // Call MyBase.OnMouseMove to activate the delegate.
        base.OnMouseMove(e);
    }
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 cursor the Hand cursor when the mouse moves 
        ' over the button.
        Cursor = Cursors.Hand

        ' Call MyBase.OnMouseMove to activate the delegate.
        MyBase.OnMouseMove(e)
    End Sub

설명

이벤트가 발생하면 대리자를 통해 이벤트 처리기가 호출됩니다. 자세한 내용은 이벤트 처리 및 발생합니다.

또한 OnMouseHover 메서드를 사용하면 파생 클래스가 대리자를 연결하지 않고도 이벤트를 처리할 수 있습니다. 이는 파생 클래스에서 이벤트를 처리하는 기본 방법입니다.

상속자 참고

파생 클래스에서 OnMouseHover(EventArgs)를 재정의하는 경우 등록된 대리자가 이벤트를 받도록 기본 클래스의 OnMouseHover(EventArgs) 메서드를 호출해야 합니다.

적용 대상

추가 정보