Ergebnis 1 bis 2 von 2
  1. #1
    Kevin Mitnick Avatar von Montaxx
    Registriert seit
    28.10.2007
    Beiträge
    1.045

    Standard [VB.Net] Fenster bewegen mit festhalten

    Viele fragen sich: "Wie kann ich ein Fenster bewegen das keine Form mehr hat, indem ich es irgendwo festhalte"

    Hier die Antwort:

    Code:
        Private CurrentPosition As New System.Drawing.Point
        Private MouseButton As System.Windows.Forms.MouseButtons = Nothing
    
        Private Overloads Sub OnMouseDown(ByVal Sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
    
            MyClass.MouseButton = e.Button()
            With MyClass.CurrentPosition
                .X = e.X()
                .Y = e.Y()
            End With
    
        End Sub
    
        Private Overloads Sub OnMouseMove(ByVal Sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
    
            Select Case MouseButton
                Case Is = Windows.Forms.MouseButtons.Left
                    MyClass.Top = Windows.Forms.Cursor.Position.Y() - MyClass.CurrentPosition.Y()
                    MyClass.Left = Windows.Forms.Cursor.Position.X() - MyClass.CurrentPosition.X()
                Case Is = Nothing
                    Exit Sub
            End Select
        End Sub
    
        Private Overloads Sub OnMouseUp(ByVal Sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
            MyClass.MouseButton = Nothing
        End Sub
    Einfach i-wo reinhauen, und das Problem ist gelößt



    MFG

    Montaxx



  2. #2

    Standard

    Code:
     Dim newPoint As New System.Drawing.Point()
        Dim a As Integer
        Dim b As Integer
    
        Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
            a = Control.MousePosition.X - Me.Location.X
            b = Control.MousePosition.Y - Me.Location.Y
        End Sub
    
        Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
            If e.Button = MouseButtons.Left Then
                newPoint = Control.MousePosition
                newPoint.X = newPoint.X - (a)
                newPoint.Y = newPoint.Y - (b)
                Me.Location = newPoint
            End If
        End Sub
    So mach ich das immer (bsp mit Picturebox1)
    und is bissl kleinerer code

Stichworte

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •