Results 1 to 14 of 14

Thread: [RESOLVED] Drag and drop question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    Tennessee
    Posts
    378

    Resolved [RESOLVED] Drag and drop question

    Hello,


    I set a frame's DragMode property to automatic and then wrote the following code into the Form_DragDrop event.

    Code:
    Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
    Source.Top = Y
    Source.Left = X
    End Sub

    [/code]

    The frame's outline would move, but the frame snapped back to where it was. What can I do?
    Thanks,
    GARY

  2. #2
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: Drag and drop question

    are you trying to move an object? or drag n drop it somewhere?
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    Tennessee
    Posts
    378

    Re: Drag and drop question

    I want to move a frame to anywhere on the screen.
    Thanks,
    GARY

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Drag and drop question

    The following quick sample should get you started:
    Code:
    Option Explicit
    
    Dim offsetX As Single
    Dim offsetY As Single
    
    Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
        Frame1.Drag vbEndDrag
        Frame1.Move X - offsetX, Y - offsetY
    End Sub
    
    Private Sub Frame1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        offsetX = X
        offsetY = Y
        Frame1.Drag vbBeginDrag
    End Sub

  5. #5
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: Drag and drop question

    Use:

    Private Declare Function ReleaseCapture Lib "user32" () As Long
    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


    And then in the Mouse_Down event of the Frame:

    ReleaseCapture
    SendMessage Frame1.hWnd, &H112, &HF012&, 0
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    Tennessee
    Posts
    378

    Re: Drag and drop question

    I've still got the same problem. The outline moves but snaps back into place.
    Thanks,
    GARY

  7. #7

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    Tennessee
    Posts
    378

    Re: Drag and drop question

    Thanks.

    Not quite what I need. I need it to stay where I drop it and not snap into another spot.
    Thanks,
    GARY

  9. #9
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Drag and drop question

    Quote Originally Posted by GARY MICHAEL View Post
    I've still got the same problem. The outline moves but snaps back into place.
    New cursor location must be outside of original boundaries so form's DragDrop event is triggered.
    Otherwise of course it will as you say "snap back".

  10. #10
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: Drag and drop question

    Use My code.. It doesn't Snap BACK.
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  11. #11
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Drag and drop question

    Exactly! Someone overlooked it maybe because it's not posted with the CODE tags...
    Anyway, all credits go to some1uk03:
    Code:
    Option Explicit
    
    Private Declare Function ReleaseCapture Lib "user32" () As Long
    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 Sub Frame1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        ReleaseCapture
        SendMessage Frame1.hWnd, &H112, &HF012&, 0
    End Sub

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    Tennessee
    Posts
    378

    Re: Drag and drop question

    Some1UK03,

    I did try your code and had the same problem, then I loaded a new form and only used your code and it worked.

    Could there be something here that interferes with your code?

    Code:
    Option Explicit
    Option Compare Text
    
    Private Declare Function ReleaseCapture Lib "user32" () As Long
    
    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 SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    
    Private Const EM_LINEFROMCHAR = &HC9
    
    Private Const EM_GETLINECOUNT = &HBA
    
    Private Const EM_LINESCROLL = &HB6
    
    Private Const EM_GETFIRSTVISIBLELINE = &HCE
    
    Private Declare Function OSWinHelp% Lib "user32" Alias "WinHelpA" (ByVal hWnd&, ByVal HelpFile$, ByVal wCommand%, dwData As Any)
    
    Private Sub MultiSearchFrame_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    ReleaseCapture
    SendMessage MultiSearchFrame.hWnd, &H112, &HF012&, 0
    
    End Sub
    Thanks,
    GARY

  13. #13
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: Drag and drop question

    Have you changed your Drag&Drop properties back to normal? Might be interfering.
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    Tennessee
    Posts
    378

    Re: Drag and drop question

    That was it. I never would have figured that out. Thak you everyone. You guys are good.
    Last edited by GARY MICHAEL; Mar 8th, 2010 at 09:40 AM.
    Thanks,
    GARY

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