VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Create New Controls At Runtime

by Marc A. Foumberg (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (6 Votes)

This code will allow you to create a new instance of a control
at runtime !
Imagine. When your app is RUNNING you can create a new command button
or a textbox on the fly ! The code they didn't want you to know ;)

API Declarations
NONE

Rate Create New Controls At Runtime

'Create a new project.
'Add a command button.
'Name the button...
' Command1(0)
'As if it were an aray.
'Its sometimes easyier to create
'an aray to begin with. If you do
'be sure to delete all button except
'Command1(0).
'The Code...
Private Sub Command1_Click(Index As Integer)
Static I As Integer
I = I + 1
Load Command1(I)
Command1(I).Left = Command1(I - 1).Left + 200
Command1(I).Top = Command1(I - 1).Top + 600
Command1(I).Caption = "New Button !"
Command1(I).Visible = True
End Sub
'At runtime this will create a new
'command button.
'To add additional function you could add
'an IF statement. As follows...
Private Sub Command1_Click(Index As Integer)
On Error GoTo Handler1
'Create new button
Static I As Integer
I = I + 1
Load Command(I)
Command(I).Left = 2460
Command(I).Top = 5520
Command(I).Caption = "For Real This Time" ' change the caption
Command(I).Visible = True
' Code to unload the form when the new button is clicked
If Command(1) Then
Unload Me
End If
Handler1:
End Sub
'Email Marc at [email protected] with any questions.
'try this with other controls !

Download this snippet    Add to My Saved Code

Create New Controls At Runtime Comments

No comments have been posted about Create New Controls At Runtime. Why not be the first to post a comment about Create New Controls At Runtime.

Post your comment

Subject:
Message:
0/1000 characters