Control.OnMouseMove(MouseEventArgs) メソッド

定義

MouseMove イベントを発生させます。

C#
protected virtual void OnMouseMove(System.Windows.Forms.MouseEventArgs e);

パラメーター

e
MouseEventArgs

イベント データを格納している MouseEventArgs

次のコード例では、派生クラスの OnMouseHover メソッドと OnMouseMove メソッドをオーバーライドする方法を示します。 この例を実行するには、次のコードを新しいフォームに貼り付け、このクラスを貼り付けて、同じファイルをフォームの後に貼り付けます。 型 FunButton のボタンをフォームに追加します。

C#
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);
    }

注釈

イベントを発生させると、イベント ハンドラーがデリゲートから呼び出されます。 詳細については、処理とイベントの発生 を参照してください。

OnMouseMove メソッドを使用すると、デリゲートを結び付けずに、派生クラスでイベントを処理することもできます。 派生クラスでイベントを処理する場合は、この手法をお勧めします。

注意 (継承者)

派生クラスで OnMouseMove(MouseEventArgs) をオーバーライドする場合は、登録されているデリゲートがイベントを受け取ることができるように、基本クラスの OnMouseMove(MouseEventArgs) メソッドを呼び出してください。

適用対象

製品 バージョン
.NET Framework 1.1, 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

こちらもご覧ください