Results 1 to 3 of 3

Thread: Moving a textbox at runtime

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    88
    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.

  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    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])

  3. #3
    Addicted Member
    Join Date
    Jul 2000
    Location
    California
    Posts
    154
    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]

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