Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Doesn't display created object at runtime 1

Status
Not open for further replies.

WomanPro

Programmer
Nov 1, 2012
180
GR
Hello everybody,
I have created a class object so that I can draw it at design in my form. But I need an array of that objects, so that I created a piece of code that does it but the objects aren't displaying at runtime. Do I miss something in my code like drawing it or something else? And how can I do that? Any help will be much appreciated.


Dim array(5) As userBtn.PcBtn_Checker
Dim i, x, y, Wdth, Hght As Integer


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
x = PcBtn_Checker1.Location.X
y = PcBtn_Checker1.Location.Y + PcBtn_Checker1.Height
Wdth = PcBtn_Checker1.Width
Hght = PcBtn_Checker1.Height
For i = 0 To 4
array(i) = New userBtn.PcBtn_Checker
array(i).SetBounds(x, y, Wdth, Hght)
array(i).Location = New Point(x, y)
x = x
y = y + PcBtn_Checker1.Height
array(i).Parent = Me.PictureBox1
Me.Controls.Add(array(i))
array(i).Show()
next
end sub
 
Maybe it's this:

array(i).Parent = Me.PictureBox1
Me.Controls.Add(array(i))

You make the controls' Parent a PictureBox, then add the controls to the Form, not the PictureBox.

Or, maybe the controls are behind the PictureBox?

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
thank you!!! when I removed Me.Controls.Add ((array(i)) statement, it worked.
But is it possible to use that statement and add each array element in the picturebox control and not to the form?
 
Yes. Instead of Me.Controls.Add ((array(i)) use PictureBox1.Controls.Add ((array(i)). Although, unless there is some reason you need to use a PictureBox, I suggest using a container control, like a Panel.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top