Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to create array of control in design time as in VB6? Is it possible or not? I know code to create that on run time..
Posted
Comments
Khaniya 28-Jul-10 9:13am    
There is no C#(.Net Framework) in VB6
Please improve your question

1 solution

Simply dim a new button and initialize the properties and place it on the form. You could access these controls by using the Controls property but you could also put them in an array or list yourself for reference. Remember that you must add them using the Controls.Add otherwise you won't see any of the newly creates controls at all.

VB
Private Sub CreatButton()
        Dim btnYes As System.Windows.Forms.Button
        ' Create control
        btnYes = New System.Windows.Forms.Button()
        ' Set button properties
        btnYes.Name = "ButtonYes"
        btnYes.Size = New System.Drawing.Size(70, 30)
        btnYes.Location = New System.Drawing.Point(300, 30)
        btn.TabIndex = 1
        btnYes.Text = "YES"
        ' add to the parent form's controls collection
        Me.Controls.Add(btnYes)
End Sub


Good luck!
 
Share this answer
 
Comments
Toli Cuturicu 28-Jul-10 9:49am    
Reason for my vote of 1
Read the question carefully before answering!
E.F. Nijboer 31-Jul-10 11:38am    
What didn't I read carefully enough? I explained how to create a dynamic control in VB.NET because the question was about VB6. The conversion to C# would be almost the same and easy to convert if one would simply have some knowledge of .NET

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900