-
Hi everybody,
Anyone knows how to move a textbox at runtime? I try to do thing like I can drag the textbox around the form at runtime, and then when I release the mouse button, the textbox stays there at the point I released the mouse button. Thanks for your help or any suggestion.
-
You change the Top and Left properties of the textbox.
Put code into the "MouseDown" events.
Don't forget however that you place your mouse pointer is "within" the textbox is offset from the top corner of the actual form itself... or for that matter from the actual Cursor Position on the screen.
You need to perform a calculation to determine the actual mouse position on the screen and based on its original offset from the topleft corner of the control you re-adjust the actual position relative to this difference.
Break the problem down into portions... such as "mousedown and mouseup", "reposition", "determine cursor position", "calculate offset".. and then solve each one individually and bring them together to function as a coherant result.
It is a very good one to try in learning how to program and problem solve at the same time.
Note : API Call GetCursorPos works on Pixels not TWIPS which is what the VB Coordinate system uses (1 Pixel = 15 Twips for standard screens [use Screen.TwipsPerPixelX])
-
Do you mean you want to move a text box with the mouse?
If you do.
Here's one way to do that.
Set textbox the dragmode to automatic and
Put this code in form
Private Sub Form_DragDrop(Source As Control, x As Single, y As Single)
Source.Move x, y
End Sub
[Edited by Bjwbell on 10-04-2000 at 01:10 AM]