VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Add Controls (i.e. TextBox) on the form dynamically during runtime

by Deep Softwares (2 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Fri 8th December 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)

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



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

Download this snippet    Add to My Saved Code

Add Controls (i.e. TextBox) on the form dynamically during runtime Comments

No comments have been posted about Add Controls (i.e. TextBox) on the form dynamically during runtime. Why not be the first to post a comment about Add Controls (i.e. TextBox) on the form dynamically during runtime.

Post your comment

Subject:
Message:
0/1000 characters