Does anyone know how to add controls at runtime?
dim btn as new button '?
I want to add an array of user controls which I have created and I'm stumped!
Thanks....
Printable View
Does anyone know how to add controls at runtime?
dim btn as new button '?
I want to add an array of user controls which I have created and I'm stumped!
Thanks....
I haven't tried that, but... here is the link:
http://support.microsoft.com/directo...308433&SD=MSDN
Looks good Akim! Thanks! ;)
Dim Form2 as New Form()
Dim btnCancel as New Button()
'set button properties
btnCancel.text = "Cancel"
btnCancel.Location = New Point(110,100)
'add new object to control collection
Form2.Controls.Add(btnCancel)
'show form as DialogBox
Form2.ShowDialog()
another example------------------------------------------
VB6 (This code adds a TextBox to the form and makes it visible.)
Dim myControl As Control
Set myControl = Me.Controls.Add("VB.TextBox", "myControl")
myControl.Visible = True
'remove control
Me.Controls.Remove "myControl"
VB.NET
Dim c As Control
c = New TextBox()
c.Name = "myControl"
Me.Controls.Add(c)
In Windows Forms, controls are indexed by number, not by name. To remove a control by name, you have
to iterate through the controls collection, find the control, and remove it. The following code shows how
to remove the newly added control by name:
Dim c As Control
For Each c In Me.Controls
If c.Name = "myControl" Then
Me.Controls.Remove(c)
Exit For
End If
Next
Here is THE MAN :)
Thanks Iouri.