Mouse Enter / Hover / Leave : Mouse Event « GUI Windows Forms « C# / CSharp Tutorial






Mouse Enter / Hover / Leave
using System;
using System.Drawing;
using System.Windows.Forms;

public class MouseEnterHoverLeave : Form
{
  private Button btn;
  string str = "";

  public MouseEnterHoverLeave()
  {
    Size = new Size(400,400);

    btn = new Button();
    btn.Parent = this;
    btn.Location = new Point(50,50);
    btn.Size = new Size(150,25);
    btn.MouseEnter += new System.EventHandler(btn_MouseEnter);
    btn.MouseHover += new System.EventHandler(btn_MouseHover);
    btn.MouseLeave += new System.EventHandler(btn_MouseLeave);
  }

  static void Main() 
  {
    Application.Run(new MouseEnterHoverLeave());
  }

  private void btn_MouseEnter(object sender, EventArgs e)
  {
    btn.Text = "MouseEnter";
  }

  private void btn_MouseHover(object sender, EventArgs e)
  {
    btn.Text = "MouseHover";
  }

  private void btn_MouseLeave(object sender, EventArgs e)
  {
    btn.Text = "MouseLeave";
  }

  protected override void OnMouseEnter(EventArgs e)
  {
    base.OnMouseEnter(e);
    Console.WriteLine("Form MouseEnter");
  }

  protected override void OnMouseHover(EventArgs e)
  {
    base.OnMouseHover(e);
    Console.WriteLine("Form MouseHover");
  }

  protected override void OnMouseLeave(EventArgs e)
  {
    base.OnMouseLeave(e);
    Console.WriteLine("Form MouseLeave");
  }
}








23.62.Mouse Event
23.62.1.Mouse Event information
23.62.2.Mouse PropertiesMouse Properties
23.62.3.Mouse event handlersMouse event handlers
23.62.4.Mouse Enter / Hover / LeaveMouse Enter / Hover / Leave
23.62.5.Mouse Button Left clicked