
Drag Text Box In Run Time
cstang,
Never tried this, but (I think) you'll need to code the
TextBox's _MouseDown Event and the Form's _DragDrop Event.
In the TextBox _MouseDown Event, capture the position (X & Y
coordinates) - this is the position of the mouse within the
TextBox.
Private Sub Text1_MouseDown(Button As Integer, Shift As
Integer, X As Single, Y As Single)
SavedX = X
SavedY = Y
End Sub
In the Form's _DragDrop Event, issue a Move command on the
TextBox using the X and Y coordinates (of the Mouse on the
Form) and the saved position (say, SavedX & SavedY) from
inside the textBox, something like :
Private Sub Form_DragDrop(Source As Control, X As Single,
Y As Single)
If TypeOf Source Is TextBox Then
Source.Move X - SavedX, Y - SavedY
End if
End Sub
If you just use X and Y in the _DragDrop Event, it will always
put the top-left corner of the TextBox at the mouse position;
this way the [relative] position of the mouse within the
TextBox is preserved.
Oh, and remember to set the TextBoxes DragMode to 1 -
"Automatic".
HTH,
Phill W.
Quote:
> Hello,
> How to allow a user to drag and place
> a text box to the require position?
> Newbie
> CSTANG