-
January 5th, 2010, 01:07 PM
#1
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?
-
January 5th, 2010, 09:09 PM
#2
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
-
January 6th, 2010, 12:08 AM
#3
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!
-
January 6th, 2010, 01:17 AM
#4
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)
-
January 6th, 2010, 09:12 AM
#5
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.
-
January 6th, 2010, 07:29 PM
#6
Re: dragr frames at run time
Originally Posted by vb5prgrmr
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.
-
January 6th, 2010, 10:47 PM
#7
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.
-
January 7th, 2010, 07:21 AM
#8
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.
-
January 7th, 2010, 10:37 PM
#9
Re: dragr frames at run time
Substitute another box inside. Dotted lines?
-
January 8th, 2010, 08:38 AM
#10
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.
-
January 27th, 2010, 11:13 PM
#11
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.
-
January 28th, 2010, 02:23 PM
#12
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.
-
January 29th, 2010, 02:33 AM
#13
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.
-
January 29th, 2010, 07:15 AM
#14
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.
-
January 29th, 2010, 07:42 AM
#15
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.
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
|