Mouse Events Illustation : Mouse Event « Event « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Event » Mouse Event 
11.7.1.Mouse Events Illustation
Mouse Events Illustation
Option Strict On
imports System
imports System.Drawing
imports System.Windows.Forms

public class MouseEvents : inherits Form

  private lbl as Label
  private WithEvents btnReset as Button

  public sub New()
    Size = new Size(400,600)

    btnReset = new Button()
    btnReset.Parent = me
    btnReset.Location = new Point(250,50)
    btnReset.Text = "Reset"

    lbl = new Label()
    lbl.Parent = me
    lbl.Location = new Point(50,50)
    lbl.Size = new Size(250,250)
    lbl.BorderStyle = BorderStyle.Fixed3D
    
    AddHandler lbl.MouseEnter, AddressOf lbl_MouseEnter
    AddHandler lbl.MouseHover, AddressOf lbl_MouseHover
    AddHandler lbl.MouseLeave, AddressOf lbl_MouseLeave
    AddHandler lbl.MouseDown, AddressOf lbl_MouseDown
      AddHandler lbl.MouseMove, AddressOf lbl_MouseMove
    AddHandler lbl.MouseUp, AddressOf lbl_MouseUp
    AddHandler lbl.MouseWheel, AddressOf lbl_MouseWheel
    AddHandler lbl.Click, AddressOf lbl_Click
    AddHandler lbl.DoubleClick, AddressOf lbl_DoubleClick

  end sub

  public shared sub Main() 
    Application.Run(new MouseEvents())
  end sub

  private sub btnReset_Click(ByVal sender as object, _
                 ByVal e as EventArgs_
                   Handles btnReset.Click
    lbl.Text = ""
  end sub

  private sub lbl_MouseEnter(ByVal sender as object, _
                 ByVal e as EventArgs)
    lbl.Text = "MouseEnter"
    Console.WriteLine("Label MouseEnter")
  end sub

  private sub lbl_MouseHover(ByVal sender as object, _
                 ByVal e as EventArgs)
    lbl.Text = "MouseHover"
    Console.WriteLine("Label MouseHover")
  end sub

  private sub lbl_MouseLeave(ByVal sender as object, _
                 ByVal e as EventArgs)
    lbl.Text = "MouseLeave"
    Console.WriteLine("Label MouseLeave")
  end sub

  private sub lbl_MouseDown(ByVal sender as object, _
                ByVal e as MouseEventArgs)
    lbl.Text = "MouseDown"
    Console.WriteLine("Label MouseDown")
    Console.WriteLine("Button:  " + e.Button.ToString())
    Console.WriteLine("Clicks:  " + e.Clicks.ToString())
    Console.WriteLine("Delta:  " + e.Delta.ToString())
    Console.WriteLine("X:  " + e.X.ToString())
    Console.WriteLine("Y:  " + e.Y.ToString())
  end sub

  private sub lbl_MouseMove(ByVal sender as object,ByVal e as MouseEventArgs)
    lbl.Text = "MouseMove"
    Console.WriteLine("Label MouseMove")
    Console.WriteLine("Button:  " + e.Button.ToString())
    Console.WriteLine("Clicks:  " + e.Clicks.ToString())
    Console.WriteLine("Delta:  " + e.Delta.ToString())
    Console.WriteLine("X:  " + e.X.ToString())
    Console.WriteLine("Y:  " + e.Y.ToString())
  end sub

  private sub lbl_MouseUp(ByVal sender as object, _
                ByVal e as MouseEventArgs)
    lbl.Text = "MouseUp"
    Console.WriteLine("Label MouseUp")
    Console.WriteLine("Button:  " + e.Button.ToString())
    Console.WriteLine("Clicks:  " + e.Clicks.ToString())
    Console.WriteLine("Delta:  " + e.Delta.ToString())
    Console.WriteLine("X:  " + e.X.ToString())
    Console.WriteLine("Y:  " + e.Y.ToString())
  end sub

  private sub lbl_MouseWheel(ByVal sender as object,ByVal e as MouseEventArgs)
    lbl.Text = "MouseWheel"
    Console.WriteLine("Label MouseWheel")
    Console.WriteLine("Button:  " + e.Button.ToString())
    Console.WriteLine("Clicks:  " + e.Clicks.ToString())
    Console.WriteLine("Delta:  " + e.Delta.ToString())
    Console.WriteLine("X:  " + e.X.ToString())
    Console.WriteLine("Y:  " + e.Y.ToString())
  end sub

  private sub lbl_Click(ByVal sender as object,ByVal e as EventArgs)
    lbl.Text = "Click"
    Console.WriteLine("Label Click")
  end sub

  private sub lbl_DoubleClick(ByVal sender as object,ByVal e as EventArgs)
    lbl.Text = "DoubleClick"
    Console.WriteLine("Label DoubleClick")
  end sub

  protected overrides sub OnMouseEnter(ByVal e as EventArgs)
    myBase.OnMouseEnter(e)
    Console.WriteLine("Form MouseEnter")
  end sub

  protected overrides sub OnMouseHover(ByVal e as EventArgs)
    myBase.OnMouseHover(e)
    Console.WriteLine("Form MouseHover")
  end sub

  protected overrides sub OnMouseLeave(ByVal e as EventArgs)
    myBase.OnMouseLeave(e)
    Console.WriteLine("Form MouseLeave")
  end sub

end class
11.7.Mouse Event
11.7.1.Mouse Events IllustationMouse Events Illustation
11.7.2.Mouse move eventMouse move event
11.7.3.Form mouse move eventForm mouse move event
11.7.4.Mouse Enter and LeaveMouse Enter and Leave
11.7.5.Double and single clickDouble and single click
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.