Thursday, July 21, 2016

VB 2010 Mouse Events

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

   

    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown

        If e.Button = MouseButtons.Left Then

            Me.BackColor = Color.AliceBlue
        ElseIf e.Button = MouseButtons.Right Then
            Me.BackColor = Color.Chocolate


        End If

    End Sub

    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        Label1.Text = "X= " & e.X & "  " & "Y = " & e.Y

    End Sub



    Private Sub Form1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel


        Dim r, g, b As Integer

        r = e.X
        g = e.Y




        If r > 255 Then
            r = r / 255

        End If
        If g > 255 Then
            g = g / 255

        End If
        Me.BackColor = Color.FromArgb(r, g, 150)
    End Sub
End Class

No comments: