|
-
Jun 12th, 2000, 07:55 PM
#1
Hi there!
I have a kind of tricky problem (or I'm simply to dumb )
I want to move a control around my form. To put my Button
on the right place after the drop I save the mouse-offset.
Code:
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (Button = vbLeftButton) Then
m_sX = X
m_sY = Y
Command1.Drag vbBeginDrag
End If
End Sub
If for example I start the Drag in the lower right corner of
the MousePointer stays in the same relative position to the
Drag-Rectangle when I move around the Form.
So far so good.
However sometimes the MousePointer moves to the center of the Drag-Rectangle after the BeginDrag
(about once in 15 attempts). In this case my DragDrop function doesn't put the Button in the right place.
This is not good.
Code:
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
With Source
.Left = X - m_sX
.Top = Y - m_sY
End With
End Sub
Thanks in advance for any advice.
best regards
da_bob
____________________
-
Jun 13th, 2000, 11:00 AM
#2
Fanatic Member
See the help file
I can't remember the code but its in the help file
Under Dragdrop
The theory is:
you use a label control to show the border and outline of the contorl you wish to drag (whatever it is, button listbox etc)
and you use the position of the label (which is initially resized to the size of the required control) therefore,
wherever you droop the label is where your source control will end up
DocZaf
{;->
-
Jun 13th, 2000, 01:00 PM
#3
Thanks for your interest Zaf Khan!
But it doesn't make a difference whether I drag the Control
(e.g. CommandButton) itself or a label instead.
The problem stays the same.
Mostly the MousePointer is in the same position to the
DragRectangle as it was to the Control before I started the Drag.
Sometimes (as explained) it appears centered instead.
It would also help me only to know which case ocurred i could
re-calculate the mouse-offset.
I didn't recognize this problem before working with SP3.
Do you think that this could be a reason?
Please help me if you have any further idea.
Thanks in advance,
da_bob
__________________
[Edited by da_bob on 06-14-2000 at 08:10 AM]
-
Jun 13th, 2000, 01:36 PM
#4
Sorry wrong suspicion!
Without SP3 the problem occurs even more often.
(about once in four tries)
I think I'll work around that problem before I go .
I'll try to center the mouse to the control before starting the drag.
Anyway anyone knows a proper solution please ...
_____________________
... only few things are worse than a working day starting this way ...
-
Jun 13th, 2000, 01:51 PM
#5
It's me again
Finally I've got it! 
You are so right Zaf Khan. It's in the DragDrop section of
the MSDN. I should have looked it up before.
If you prevent the control you want to drag from getting the focus the problem doesn't occur.
Code:
Private Sub cmdDrag_GotFocus()
cmdDummy.SetFocus
End Sub
Sorry for taking your time guys!
It's a beautiful day! Yep! Yippie!
Thanks again Zaf Khan!
Keep on coding!
da_bob
___________________
-
Jun 13th, 2000, 02:44 PM
#6
If nobody wants to talk to me I'll make up my own thread !
The GotFocus trick works well for Buttons but I have to Drag a VC6 ocx.
Damn, the trick doesn't effect them - I don't know why.
Is there anybody who does?
So I'll go back to the cursor-moving workaround.
Regards
da_bob
____________________
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
|