dynamicly add my custom control
hi all i have made a control which is just a ui feature
however i would like to create the UI Control ex number of times in my form
i guess something like this
Dim HealthCtl As Control
For i As Integer = 1 To 5
HealthCtl = New HB_Server.Health
HealthCtl.Name = "HealthCtl" & i
HealthCtl.Location = New System.Drawing.Point(8, i & 8)
HealthCtl.Show()
Next
but i dont think its right Can someone help me
thanks in advance
Re: dynamicly add my custom control
I know you can just create a new instance of your control specifically like this
For i As Integer = 1 To 5
dim HealthCtl as New HB_Server.Health
HealthCtl.Name = "HealthCtl" & i
HealthCtl.Location = New System.Drawing.Point(8, i & 8)
HealthCtl.Show()
Next
instead of
Quote:
Dim HealthCtl As Control
For i As Integer = 1 To 5
HealthCtl = New HB_Server.Health
HealthCtl.Name = "HealthCtl" & i
HealthCtl.Location = New System.Drawing.Point(8, i & 8)
HealthCtl.Show()
Next
That is how i have used dynamic controls before. hope that helps a little
Edit: I don't know how well that HealthCtl.Location line will work. "i & 8" I assume would "add" i and 8 so on 1 it would be 9... All your controls (if taller than 1 pixel) will overlap. in which case you can use multiplication.
HealthCtl.Location = New Point(8, (i * HealthCtl.Height) + 8)
which if i am thinkin correctly will move the control down 8 pixels under the one before it. It might take a little playing with though I get confused when it comes to logic since I lack quite a bit of that
Re: dynamicly add my custom control
Once you have dynamically created the control, you have to add it to the controls collection of the container (form, pane, pic box, etc) in order for it to work.
Tg