Results 1 to 5 of 5

Thread: Borderless form - how to make "draggable"

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Posts
    3

    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

  2. #2
    Hyperactive Member wordracr's Avatar
    Join Date
    Aug 2001
    Posts
    281
    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:
    1. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd _
    2. As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    3.  
    4. Private Declare Function ReleaseCapture Lib "user32" () As Long
    5.  
    6. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    7.  
    8.     ReleaseCapture
    9.     SendMessage Me.hWnd, &HA1, 2, 0&
    10.  
    11. End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Posts
    3
    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Posts
    3
    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)

  5. #5
    Member
    Join Date
    Jul 2002
    Posts
    32
    This is nearly correct, but better try this:

    VB Code:
    1. Private objMouseOffset As Point
    2.  
    3.  
    4. Private Sub Movement_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)  Handles MyBase.MouseDown
    5.     ' save the mouse start position
    6.     objMouseOffset = New Point(e.X, e.Y)
    7. End Sub
    8. Private Sub Movement_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
    9.     If Not e.Button = MouseButtons.Left Then Exit Sub
    10.     ' create a point and calculate the offset from mouse movement
    11.     Dim objRelativeMovement As Point = Me.Location
    12.     objRelativeMovement.Offset(e.X - objMouseOffset.X, e.Y -objMouseOffset.Y)
    13.     ' set the new form location
    14.     Me.Location = objRelativeMovement
    15. 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
  •  



Click Here to Expand Forum to Full Width