Results 1 to 4 of 4

Thread: Using 'SendMessage' to manually drag a form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2001
    Posts
    83

    Question Using 'SendMessage' to manually drag a form

    Hi,
    I have managed to allow a form to be dragged by using the _MouseDown Sub that is triggered with a picturebox upon mouse down...

    It works quite well, however 'ReleaseCapture' is also used, and this prevents _MouseUp from being triggered.

    Why is this important you may ask?
    Becuase on _MouseDown, 'pic_Caption.BackColor = 255' is used (pic_Caption is the picturebox name) changing the color of the picturebox to red, which signified that the user is dragging the window.

    So I need something to be triggered when the user has stopped dragging the form to return pic_Caption.BackColor to it's original color, which is black.

    'pic_Caption.BackColor = 0'

    Please take a look at the source included and share your idea's/solutions.

    Thanks,
    Sphynx

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    I use the following code to simulate a mouseover/mouseleave event. When the mouse is over my command button, I change the backcolor to cyan, and when the mouse has left my button I change it back to the standard gray
    VB Code:
    1. If (X < 0) Or (Y < 0) Or (X > cmdAbout.Width) Or (Y > cmdAbout.Height) Then ' the MOUSELEAVE pseudo-event
    2.                ReleaseCapture ' the mouse is no longer over the button, change backcolor to gray
    3.                cmdAbout.BackColor = &HC0C0C0
    4.         ElseIf GetCapture() <> cmdAbout.hWnd Then ' the MOUSEENTER pseudo-event
    5.                SetCapture cmdAbout.hWnd ' the mouse is over the button, change backcolor to cyan
    6.                cmdAbout.BackColor = vbCyan
    7.         End If
    Problem: When a user clicks the button it remained cyan even after the mouse had left. Solution: I put
    VB Code:
    1. ReleaseCapture
    2. cmdAbout.BackColor = &HC0C0C0
    in the buttons click event. So, my suggestion would be to change your mouseevent to the following
    VB Code:
    1. Private Sub pic_Caption_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2. pic_Caption.BackColor = 255
    3. If Button = 1 Then On Error Resume Next: FormDrag Me
    4. ReleaseCapture
    5. pic_Caption.BackColor = 0
    6. End Sub
    PS: I did this on your form and it worked like a champ.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2001
    Posts
    83

    Smile Manual Dragging.. AND Resizing :)

    Hey, thanks for the help Hack.
    I've added some more code and come across a new problem, I wanted to allow the window to be resized manually.

    See if you can help me out and check out the code attached.

    Thanks,
    Sphynx
    Last edited by sphynx; Oct 27th, 2001 at 01:25 PM.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2001
    Posts
    83

    oops :/

    Sorry, try this file.

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