Add Controls (i.e. TextBox) on the form dynamically during runtime
Add Controls (i.e. TextBox) on the form dynamically during runtime
API Declarations
Type in the code in the code window of the form module.
Rate Add Controls (i.e. TextBox) on the form dynamically during runtime
(2(2 Vote))
Private tValue As Long, cIndx As Integer, ctrlName As String
Private Sub Command1_Click()
cIndx = cIndx + 1
tValue = tValue + 400
ctrlName = "DynTxtBx" & CStr(cIndx)
Set txtObject = Form1.Controls.Add("VB.TextBox", ctrlName)
With txtObject
.Visible = True
.Left = 250
.Width = 4000
.Height = 250
.Top = tValue
.Text = "This is a dynamically created TextBox No." & CStr(cIndx)
End With
If Not Command2.Enabled Then Command2.Enabled = True
End Sub
Private Sub Command2_Click()
Form1.Controls.Remove ctrlName
cIndx = cIndx - 1: tValue = tValue - 400
ctrlName = "DynTxtBx" & CStr(cIndx)
If cIndx = 0 Then Command2.Enabled = False
End Sub
Add Controls (i.e. TextBox) on the form dynamically during runtime Comments
No comments yet — be the first to post one!
Post a Comment