|
-
May 21st, 2002, 03:31 PM
#1
Adding Controls at Runtime
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....
-
May 21st, 2002, 03:55 PM
#2
Re: Adding Controls at Runtime
-
May 21st, 2002, 04:14 PM
#3
Adding Controls at Runtime
Looks good Akim! Thanks!
-
May 21st, 2002, 07:12 PM
#4
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
-
May 21st, 2002, 07:57 PM
#5
Here is THE MAN 
Thanks Iouri.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|