Picture Box und Maus Problem

  • VB.NET

Es gibt 4 Antworten in diesem Thema. Der letzte Beitrag () ist von tfshow.

    Picture Box und Maus Problem

    Halle Community,

    ich habe ein Problem, weil ich gerade ein spiel programmieren möchte:
    In meiner form soll die PictureBox beweglich sein d.h. wenn man mit der maus über die PictureBox fährt und dann linke Linke Maustaste drückt soll diese dann mit der maus beweglich sein bis man auf hört die linke maustaste zu drücken...
    Ich hoffe ihr versteht was ich meine :D

    Danke im Voraus!

    Mit freundlichen Grüßen

    VB.NET-Quellcode

    1. Dim nStartPos As Point
    2. Dim nDragPos As Point
    3. Public Sub PictureBox_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
    4. If e.Button = Windows.Forms.MouseButtons.Left Then
    5. nStartPos = Me.Location
    6. nDragPos = Me.PointToScreen(New Point(e.X, e.Y))
    7. End If
    8. End Sub
    9. Public Sub PictureBox_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
    10. If e.Button = Windows.Forms.MouseButtons.Left Then
    11. Dim nCurPos As Point = Me.PointToScreen(New Point(e.X, e.Y))
    12. Me.Location = New Point(nStartPos.X + nCurPos.X - nDragPos.X, _
    13. nStartPos.Y + nCurPos.Y - nDragPos.Y)
    14. End If
    15. End Sub


    Gruß Vitox