ziehen/ Verschieben von Panels

  • VB.NET

Es gibt 7 Antworten in diesem Thema. Der letzte Beitrag () ist von HerrBert.

    ziehen/ Verschieben von Panels

    hallo Community :)

    Mein Problem ist eigentlich ganz simple:
    Ein Panel Hin und Hert ziehen

    Mein Code bis Jetzt:

    VB.NET-Quellcode

    1. Public Class Form1
    2. Dim dif As New Point
    3. Dim md As Boolean = False
    4. Private Sub Panel1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
    5. md = True
    6. dif = New Point(e.X, e.Y)
    7. 'MsgBox(dif.X.ToString & " - " & dif.Y.ToString)
    8. End Sub
    9. Private Sub Panel1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
    10. If md Then
    11. Panel1.Location = New Point(Cursor.Position.X + dif.X, Cursor.Position.Y + dif.Y)
    12. End If
    13. End Sub
    14. Private Sub Panel1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp
    15. md = False
    16. End Sub
    17. End Class


    Alles Klappt super, nur wenn ich das Panel ziehe Springt mir es geschätzte 150 Pixel nach schräg unten.
    Wodrin liegt mein Denkfehler?? Tipps sind willkommen...

    HerrBert
    Linux wird nie das meistinstallierte Betriebssystem sein. Bedenken Sie nur, wie oft man Windows neu installieren muss!
    :thumbsup:
    So müsste es gehen:

    VB.NET-Quellcode

    1. Public Class Form1
    2. Dim x, y As Integer
    3. Private Sub Panel1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
    4. x = MousePosition.X - e.Location.X
    5. y = MousePosition.Y - e.Location.Y
    6. End Sub
    7. Private Sub Panel1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
    8. If e.Button = Windows.Forms.MouseButtons.Left Then
    9. Panel1.Location = New Point(MousePosition.X - x, MousePosition.Y - y)
    10. End If
    11. End Sub
    12. End Class
    die Antwort von UFO funktioniert nicht richtig.. wenn ich das Panel bewege Springt es immer in die obere Ecke und von da aus kann ich es dann verschieben
    Linux wird nie das meistinstallierte Betriebssystem sein. Bedenken Sie nur, wie oft man Windows neu installieren muss!
    :thumbsup:
    Sorry, so gehts:

    VB.NET-Quellcode

    1. Public Class Form1
    2. Dim x, y As Integer
    3. Private Sub Panel1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
    4. x = MousePosition.X - Panel1.Location.X
    5. y = MousePosition.Y - Panel1.Location.Y
    6. End Sub
    7. Private Sub Panel1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
    8. If e.Button = Windows.Forms.MouseButtons.Left Then
    9. Panel1.Location = New Point(MousePosition.X - x, MousePosition.Y - y)
    10. End If
    11. End Sub
    12. End Class