Drag Text Box In Run Time 
Author Message
 Drag Text Box In Run Time

Hello,

How to allow a user  to drag and place
a text box to the require position?

Newbie
CSTANG



Wed, 18 Jun 1902 08:00:00 GMT  
 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



Wed, 18 Jun 1902 08:00:00 GMT  
 Drag Text Box In Run Time
Consider this example as a guide. Start a new project and place a TextBox on
the Form. (Leave all Name properties as their defaults). Paste this code
into the Form's code window and Run the project. If you press (and hold) the
Control key, then pressing the left mouse button while the cursor is over
the TextBox will allow you to drag it wherever you want to. (Note: I
implemented this using the Control key so that normal mouse events could be
used in the TextBox itself.) By the way, you should be able to apply this
technique to any component; just change the control names for the MouseMove
and MouseUp events and for the one With/EndWith block.

Rick

Private Type POINTAPI
  X As Long
  Y As Long
End Type

Private Declare Function GetCursorPos& Lib "user32" _
                       (lpPoint As POINTAPI)

Dim Initialized As Boolean

Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, _
                                                  X As Single, Y As Single)
  Static LastPoint As POINTAPI
  Dim CurrentPoint As POINTAPI
  If Button = 1 And (Shift And vbCtrlMask) Then
    GetCursorPos CurrentPoint
    If Not Initialized Then
      LastPoint.X = CurrentPoint.X
      LastPoint.Y = CurrentPoint.Y
      Initialized = True
    End If
    With Text1
      .Move .Left + Screen.TwipsPerPixelX * (CurrentPoint.X - LastPoint.X),
_
                 .Top + Screen.TwipsPerPixelY * (CurrentPoint.Y -
LastPoint.Y)
    End With
    LastPoint = CurrentPoint
  End If
End Sub

Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single,
Y As Single)
  Initialized = False
End Sub



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Dragging a Text Box at run-time

2. loading text boxes at run-time

3. changing the datasource property of a text box at run time

4. HELP: Adding text boxes during run time

5. New Text Box during Run-time

6. Text Box during run time

7. make new text-boxes at run-time

8. Resizing a text box at run time.

9. Create Text Box or Label at Run Time ?

10. Run-time control of rich text box scroll bar visibility

11. Creating new text boxes at run time

12. Creating new text boxes at run time

 

 
Powered by phpBB® Forum Software