how to create an object array with a child object.

Posted on 2009-04-14
Last Modified: 2012-05-06
Hi All!

Ok.. I have a small loop that creates a new PANEL, After each panel is created I also am creating a new LABEL within that panel.. as its child.

The problem is I only get one LABEL in the first PANEL?

Im stumped..
Thanks in Advance..

Code is below..
Dim panelx(10) As Panel

        Dim labelx(10) As Label


        CNT = 0

        Dim looper

        For looper = 1 To 9


            panelx(looper) = New Panel

            labelx(looper) = New Label


            panelx(looper).BorderStyle = BorderStyle.FixedSingle

            panelx(looper).BackColor = Color.Pink

            panelx(looper).Width = 123 * looper

            panelx(looper).Height = 123

            panelx(looper).Location = New Point(10, 10)






            ToolTip1.SetToolTip(panelx(looper), looper)

            ToolTip1.SetToolTip(labelx(looper), ".." & looper)


            labelx(looper).Location = New Point(-1, -2)

            labelx(looper).MinimumSize = New Size(24, 24)

            labelx(looper).Size = New Size(24, 24)

            labelx(looper).TextAlign = ContentAlignment.MiddleCenter

            labelx(looper).BackColor = Color.GreenYellow

            labelx(looper).Text = looper.ToString




        Next looper

Open in new window

Question by:jellydeal
  • 2
  • 2
LVL 30

Accepted Solution

hnasr earned 500 total points
ID: 24138374
Your code is working and labels are inserted, but overlapping panels.

Replace the hnasr commented lines and check:

            panelx(looper).Width = 123 '* looper ==== hnasr commnted the multiplication
            panelx(looper).Height = 123
            panelx(looper).Location = New Point(10 + (looper-1) * 123, 10) 'hnasr changed the left of the panel

Author Closing Comment

ID: 31569860
Thanks hnasr..
Too close to the trees to see thw woods and all that!
Thanks for your help,
much appreciated.
Kindest regards
LVL 30

Expert Comment

ID: 24141019
You are welcome!

Author Comment

ID: 24145772

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tidtcpserver connection lost handle 2 70
C# code editing and collaboration 3 98
fso.FolderExists("\\server\HiddenFolder$") 4 49
Excel Automation VBA 19 30
A short article about a problem I had getting the GPS LocationListener working.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now