CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Join Date
    Nov 2005
    Posts
    95

    dragr frames at run time

    Is it possible to allow frames on a main form to be dragged around (repositioned) on the main form by the user during the program operation (runtime?)

    What is the option needed to allow this functionality?

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: dragr frames at run time

    Seeing that it doesn't even have a handle, like most windows, it isn't possible.
    Frames are only a way of grouping what's on the form, the way it exists. If the Form size changes, the frame sizes change
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Nov 2005
    Posts
    95

    Re: dragr frames at run time

    If I turn on the Frame Drag mode property to automatic it does let me drag the frame around during run, but when I let go it goes back to where it was...so it seems like it almost does it!

  4. #4
    Join Date
    Apr 2009
    Posts
    394

    Re: dragr frames at run time

    D, D, D.... A frame does have a hwnd and so setcapture would work... Candy, please have a look at http://www.vbkeys.com/ctl5.aspx (the download link still works)

  5. #5
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: dragr frames at run time

    @vb5: good example
    @candy: your attempts would also lead to a result.
    You'd have to go to the Form_DragDrop() event which is raised when you drop the dragged frame. The event is called Form_DragDrop(Source As Control, X!, Y!) where Source is your Frame, X and Y are the mouse pointer coordinates on the Form when dropping.
    Code:
    Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
    Source.Move X, Y 
    End Sub
    The only problem is to take in account where you grabbed the frame. Mostly you wouldn't grab it at the top-left corner, but somewhere in the middle. You would have to detect the offset of the mousepointer within the dragged frame, but unfortunately you get no more Frame_MouseDown() events if the Frame's DragMode is set to Automatic.

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: dragr frames at run time

    Quote Originally Posted by vb5prgrmr View Post
    D, D, D.... A frame does have a hwnd and so setcapture would work... Candy, please have a look at http://www.vbkeys.com/ctl5.aspx (the download link still works)

    Oops. There is something unique about the frame, and I thought that was it.
    Last edited by dglienna; January 6th, 2010 at 07:34 PM.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Nov 2005
    Posts
    95

    Re: dragr frames at run time

    WOF:

    I took your thoughts and came up with the following (the frame is intialized to dragMode=Manual)
    This works very well....EXCEPT you have to move the frame a large distance before the form dragDrop will fire on mouse release...so if you need a minor position adjustment you have to set down the frame far away then pull it back into desired position...how come?

    Code:
    Private Sub Frame1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Mx = X
    My = Y      'grab mouse coordinates
    Frame1.DragMode = 1    '(automatic)
    Frame1.Drag                   'start dragging NOW
    End Sub
    '.....
    '.....
    Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
    Source.Move X - Mx, Y - My  'final resting spot
    Source.DragMode = 0         'back to manual (no dragging)
    End Sub
    Last edited by vbcandies; January 7th, 2010 at 12:31 AM.

  8. #8
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: dragr frames at run time

    This
    Code:
    Frame1.DragMode = 1    '(automatic)
    Frame1.Drag                   'start dragging NOW
    is clever. So you get the offset of the mouse pointer within the frame.
    To answer your question:
    Set a breakpoint in the Form_DragDrop() event and try dragging.
    As long as the mouse pointer is on the frame you try to trag, the drop event of the form will not fire, because the mouse is still over the frame. The event will only fire if the mouse is over plain form client area.
    You could come by if you make the frame invisible as soon as you grab it, and visible again when you drop it. This works fine I just tried it. Only a little strange because the frame vanishes while you drag the outline of it.

  9. #9
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: dragr frames at run time

    Substitute another box inside. Dotted lines?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  10. #10
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: dragr frames at run time

    Yeah, good idea.
    Could be a simple Shape object moved to the frames original location and size at Drag start.
    Shape objects have the advantage of being "mouse-transparent", that is they do not block the mouse events from the forms client area like the Frame does.

  11. #11
    Join Date
    Nov 2005
    Posts
    95

    Re: dragr frames at run time

    I've been using the drag method described above (ignoring the fact that when you drag you see an outline)...but what I ran into (er, just noticed) is that if you drag one almost under the another it dissappears & totally vanishes even if you drag the remaining frame to the side---the one that disappeared is really gone! what is causing this vanishing act?

    Is one frame being deposited into the other? They should all just slide around on the main form.

  12. #12
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: dragr frames at run time

    Can you attach a small form with the code you are using for the moving and 2 frames where we can see the effect?
    Actually it sounds quite improbable what you are describing.

  13. #13
    Join Date
    Nov 2005
    Posts
    95

    Re: dragr frames at run time

    Hello:

    the code is as given below. The frames are indexed frames.

    Code:
    Private Sub FrameProto_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    mX = X
    mY = Y      'grab mouse coordinates
    FrameProto(Index).DragMode = 1    '(automatic)
    FrameProto(Index).Drag                   'start dragging NOW
    FrameProto(Index).Visible = False'.....
    '.....
    Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)   'main form sub
    On Error Resume Next
    Source.Move X - mX, Y - mY  'final resting spot
    Source.DragMode = 0         'back to manual (no dragging)
    Source.Visible = True
    End Sub
    Last edited by vbcandies; January 29th, 2010 at 02:40 AM.

  14. #14
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: dragr frames at run time

    Well now, there's a thing.
    Ok, I shall play around with that one. It is like when you are dropping one fram on the other it completely vanishes. This happens when the mouse pointer is over the second frame when dropping the first one. Looks like some weird bug.

  15. #15
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: dragr frames at run time

    This here reveals what happens:
    Code:
    Private Sub FrameProto_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single)
      Source.Visible = True
    End Sub
    The frame is not dropped to the form, but the other frame takes the drop event. You will see that it was not dropped to the form at all. That's why it has not changed its position and that's why Source.Visible = True in the Form_DragDrop() does not do anything: The event does not fire.
    Instead the FramProto_DragDrop() fires.
    At the start of the drag operation you make the frame invisible, remember?
    That's why it stays invisible: the Form_DragDrop() where you make it visible again did not fire.

    So its NOT a bug.

Page 1 of 2 12 LastLast

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

Featured