Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding textboxs during runtime 1

Status
Not open for further replies.

intrepid101

Programmer
Aug 8, 2001
13
0
0
US
Is it possible to allow a user to add textboxs during runtime and then be able to drag them where they want, such as creating a custom form?
thanks
Scott
 
Hi,

You can move controls (this is just one way, there are MUCH ways to do it :)) by using this code:

[tt]
Dim iLeft As Integer, iTop As Integer

Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
Source.Left = X - iLeft
Source.Top = Y - iTop
End Sub

Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
iLeft = X
iTop = Y

Text1.Drag
End Sub
[/tt]

And you can create textboxes at runtime by using this code:
1) If you have a control array of a textbox, suppose you have made a control array of Text1, which contains 1 textbox, you can add a nth one by using [tt]Load Text1(n)[/tt].

To edit this one, simply edit the control Text1(n)

2) You can really create it by using this code:

[tt]
Dim ATextbox as TextBox
Set ATextbox = Form1.Controls.Add("VB.TextBox", "key") 'if you wish you can give a third parameter, which specifies to link to a certain container
[/tt]


To edit this one, edit ATextbox (most likely you will build an array here too, if you don't know how much textboxes you will build)

Keep in mind that the textboxes have their visibility set to false, so if you use this code and you don't see anything, thats correct :)

LuCkY
 
Thank you very much Lucky, what you gave me hit the nail on the head and is very helpfull.

Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top