'Maybe the following stuff will helpHOWTO: Dynamically Add Controls to a Form with Visual Basic 6.0<br><br>SUMMARY<br>Visual Basic 6.0 allows you to dynamically add control to a form at run- time using the new Add method of the Controls collection. <br><br>MORE INFORMATION<br>The following example dynamically adds two intrinsic and one ActiveX control to an application at run-time. The sample shows how to program the events of a dynamically added control. If you are dynamically adding a control that is not referenced in the project, you may need to add the control's License key to the Licenses collection. For more information on the Licenses collection, please see the REFERENCES section of this article. <br><br>When you reference properties of the dynamically-added control, you must use the Object keyword to access the properties of the control. If you don't use the Object keyword, you will only be able to access the extender properties of the control. <br><br>When an ActiveX control is dynamically added using the VBControlExtender object and WithEvents in the declare statement, you will need to use the ObjectEvent method to code all of the control's events. If you declare an intrinsic control WithEvents, you will get all the standard event methods for the type of control you declared. You can see this by adding the following declare statement in the Code window and then checking the Events dropdown for the declared variable in the Code window: <br><br><br>Dim WithEvents cmdMyCommand as VB.CommandButton<br><br>Steps to Create Sample Project<br><br>Create a new Standard EXE project. Form1 is created by default. <br><br>Add the following code to the code window of Form1: <br><br><br> Option Explicit<br> ' If you are adding an ActiveX control at run-time that is<br> ' not referenced in your project, you need to declare it<br> ' as VBControlExtender.<br> Dim WithEvents ctlDynamic As VBControlExtender<br> Dim WithEvents ctlText As VB.TextBox<br> Dim WithEvents ctlCommand As VB.CommandButton<br><br><br> Private Sub ctlCommand_Click()<br> ctlText.Text = "You Clicked the Command button"<br> End Sub<br><br> Private Sub ctlDynamic_ObjectEvent(Info As EventInfo)<br> ' test for the click event of the TreeView<br> If Info.Name = "Click" Then<br> ctlText.Text = "You clicked " _<br> & ctlDynamic.object.selecteditem.Text<br> End If<br> End Sub<br><br> Private Sub Form_Load()<br> Dim i As Integer<br> ' Add the license for the treeview to the license collection.<br> ' If the license is already in the collection you will get<br> ' the run-time error number 732.<br> Licenses.Add "MSComctlLib.TreeCtrl"<br> ' Dynamically add a TreeView control to the form.<br> ' If you want the control to be added to a different<br> ' container such as a Frame or PictureBox, you use the third<br> ' parameter of the Controls.Add to specify the container.<br> Set ctlDynamic = Controls.Add("MSComctlLib.TreeCtrl", _<br> "myctl", Form1)<br> ' set the location and size of the control.<br> ctlDynamic.Move 1, 1, 2500, 3500<br> ' Add some nodes to the control.<br> For i = 1 To 10<br> ctlDynamic.object.nodes.Add Key:="Test" & Str(i), Text:="Test" _<br> & Str(i)<br> ctlDynamic.object.nodes.Add Relative:="Test" & Str(i), _<br> Relationship:=4, Text:="TestChild" & Str(i)<br> Next i<br> ' Make the control visible.<br> ctlDynamic.Visible = True<br> ' add a textbox<br> Set ctlText = Controls.Add("VB.TextBox", "ctlText1", Form1)<br> ' Set the location and size of the textbox<br> ctlText.Move (ctlDynamic.Left + ctlDynamic.Width + 50), _<br> 1, 2500, 100<br> ' Change the backcolor.<br> ctlText.BackColor = vbYellow<br> ' Make it visible<br> ctlText.Visible = True<br> ' Add a CommandButton.<br> Set ctlCommand = Controls.Add("VB.CommandButton", _<br> "ctlCommand1", Form1)<br> ' Set the location and size of the CommandButton.<br> ctlCommand.Move (ctlDynamic.Left + ctlDynamic.Width + 50), _<br> ctlText.Height + 50, 1500, 500<br> ' Set the caption<br> ctlCommand.Caption = "Click Me"<br> ' Make it visible<br> ctlCommand.Visible = True<br> End Sub<br><br><br>Save and run the project. Try clicking the CommandButton and on different Nodes in the TreeView. The TextBox will show what you click. <br> <br><br>