PDA

Click to See Complete Forum and Search --> : Borderless form - how to make "draggable"


int
Aug 7th, 2002, 02:24 PM
Hi, this is my first post here, hopefully i can contribute in some way despite my vb newbie status :)

My first question - I have a borderless form with a bmp background, how do I make it "draggable" by the user?

All help appreciated

wordracr
Aug 7th, 2002, 03:07 PM
Sorry to disappoint you if this isn't what you're looking for,
but this works for vb6.. maybe you can change some of it
so it works with .net.


Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd _
As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Declare Function ReleaseCapture Lib "user32" () As Long

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

ReleaseCapture
SendMessage Me.hWnd, &HA1, 2, 0&

End Sub

int
Aug 7th, 2002, 03:39 PM
Thanks wordracr, but I couldnt get that to work. It may be something obvious , Im a newbie at this, only started playing with it yesterday...

Anyhow, thanks again, i'll keep trying :)

int
Aug 7th, 2002, 05:04 PM
This seemed to do the trick.....



Private mouse_offset As Point

Private Sub form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
mouse_offset = New Point(-e.X, -e.Y)
End Sub

Private Sub form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If e.Button = MouseButtons.Left Then
Dim mousePos As Point = Control.MousePosition
mousePos.Offset(mouse_offset.X, mouse_offset.Y)
Location = mousePos
End If
End Sub


(Not my code, just posting it for others to benefit)

Josch
Aug 7th, 2002, 05:39 PM
This is nearly correct, but better try this:


Private objMouseOffset As Point


Private Sub Movement_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
' save the mouse start position
objMouseOffset = New Point(e.X, e.Y)
End Sub
Private Sub Movement_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If Not e.Button = MouseButtons.Left Then Exit Sub
' create a point and calculate the offset from mouse movement
Dim objRelativeMovement As Point = Me.Location
objRelativeMovement.Offset(e.X - objMouseOffset.X, e.Y -objMouseOffset.Y)
' set the new form location
Me.Location = objRelativeMovement
End Sub