copyright 1999 - 2014 by heinz prelle - hannover  - lenbachstraße 42 - www.visual-basic5.de | impressum
Beispiel: VB .Net - Mausbewegungen aufzeichnen und wieder abspielen
'
Option Explicit On
Option Strict On

Public Class Form1

    Private q As New Queue(Of Point)
    Private img As Image = Image.FromFile(System.IO.Path.Combine(Application.StartupPath, "totenkopf.gif"))

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles Button1.Click
        If Timer1.Enabled Then
            Timer1.Stop()
            Me.Button1.Text = "Start recording"
            Me.Button2.Enabled = True
        Else
            Timer1.Interval = 100
            Timer1.Start()
            Me.Button1.Text = "Stop recording"
            Me.Button2.Enabled = False
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles Button2.Click
        If Timer2.Enabled Then
            Timer2.Stop()
            Me.Button2.Text = "Start playing"
            Me.Button1.Enabled = True
        Else
            Timer2.Interval = 100
            Timer2.Start()
            Me.Button2.Text = "Stop playing"
            Me.Button1.Enabled = False
        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles Timer1.Tick
        Me.RecordQueue()
    End Sub

    Private Sub RecordQueue()
        Dim mp As Point = MousePosition()
        Dim sz As Size = Me.Size - Me.ClientSize
        Dim pt As Point = New Point(sz.Width \ 2, sz.Height - sz.Width \ 2)
        Dim x As Integer = mp.X - Me.Location.X - pt.X
        Dim y As Integer = mp.Y - Me.Location.Y - pt.Y
        q.Enqueue(New Point(x, y))
        Me.ListBox1.Items.Add(New Point(x, y))
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles Timer2.Tick
        Me.PlayRecordedQueue()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles MyBase.Load
        With Me
            .Text = "Mausbewegungen aufzeichnen und wieder abspielen"
            .CenterToScreen()
            .Button1.Text = "Start recording"
            .Button2.Text = "Start playning"
            .Button3.Text = "Clear queue"
            .PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
            .Button2.Enabled = False
            If Me.img IsNot Nothing Then
                .PictureBox1.Image = Me.img
            Else
                Me.Close()
            End If
        End With
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles Button3.Click
        Me.Button2.Enabled = False
        q.Clear()
        Me.ListBox1.Items.Clear()
    End Sub

    Private Sub PlayRecordedQueue()
        Dim pt As Point = q.Dequeue()
        Me.PictureBox1.Location = pt
        q.Enqueue(pt)
    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) _
            Handles Me.Paint

        'Dim rect As New Rectangle(0, 0, Me.Width, Me.Height)
        'Dim hBrush As New Drawing2D.LinearGradientBrush _
        '    ( _
        '        rect, _
        '        Color.Blue, _
        '        Color.Yellow, _
        '        Drawing2D.LinearGradientMode.Vertical _
        '    )
        'e.Graphics.FillRectangle(hBrush, rect)
    End Sub

End Class
Sourcecode Visual Basic
Download (.zip) Projektdateien