PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : [VB.Net] Fenster bewegen mit festhalten



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

Hier die Antwort:


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

Kaspersky
02.04.2009, 19:07
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