Hey..
You have 3 ways to do that I will descript you begin from simple method and terminate by complex one.
Method 1:
You can create your run-time controls first by placing Textbox control in your form and then change index property to 0 to create array of textbox control, then you can use it to load new controls at runtime, and you can receive events from all of controls by Text1 control events and use Index parameter to identify your control.
- Private Sub Command1_Click()
-
Dim TextControl As TextBox
-
ControlID = ControlID + 1
-
Load Text1(ControlID)
-
Set TextControl = Text1(ControlID)
-
With TextControl
-
.Left = (Text1(ControlID - 1).Left + Text1(ControlID - 1).Width) + 10
-
.Top = 20
-
.Width = 100
-
.Height = 20
-
.Visible = True
-
End With
-
End Sub
'================================================= =======
Method 2:
You can create new controls using Form.Controls object, but you can't receive events from VB IDE about these controls, to handle events you must work a lot using API functions.
- Private Sub Command1_Click()
-
Dim TextControl As TextBox
-
Dim PrevTextControl As TextBox
-
ControlID = ControlID + 1
-
Set TextControl = Form1.Controls.Add("Vb.TextBox", "Text" & ControlID)
-
If (ControlID > 1) Then
-
Set PrevTextControl = Form1.Controls("Text" & (ControlID - 1))
-
Else
-
Set PrevTextControl = TextControl
-
End If
-
With TextControl
-
.Left = (PrevTextControl.Left + PrevTextControl.Width) + 10
-
.Top = 20
-
.Width = 50
-
.Height = 20
-
.Visible = True
-
End With
-
End Sub
'================================================= =======
Method 3:
Using API only to create new textbox controls at run-time and sure you will work a lot to receive events and just to change the text in the textbox controls, you can use CreateWindows API Function to do that.
GOOD LUCK