|
-
Aug 7th, 2002, 02:24 PM
#1
Thread Starter
New Member
Borderless form - how to make "draggable"
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
-
Aug 7th, 2002, 03:07 PM
#2
Hyperactive Member
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.
VB Code:
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
-
Aug 7th, 2002, 03:39 PM
#3
Thread Starter
New Member
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
-
Aug 7th, 2002, 05:04 PM
#4
Thread Starter
New Member
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)
-
Aug 7th, 2002, 05:39 PM
#5
Member
This is nearly correct, but better try this:
VB Code:
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
Last edited by Josch; Aug 7th, 2002 at 05:45 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|