Results 1 to 4 of 4

Thread: [2.0] Control Array

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Location
    Cairo, Egypt
    Posts
    126

    [2.0] Control Array

    Hi All;
    I want to add controls in my program at run time. I want to use the control array and I found the solution in MSDN and I made a class like the example in it, but the problem is I want to add a control has another child control like a Panel include a PictureBox. I made it, it's easy but when I use the class to test it I have the properties of the Panel only and I don't have the properties of the PictureBox like the Image property to set the image. How could I solve this.

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2.0] Control Array

    I think you need to rephrase your question. I dont really understand what you're trying to do.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Control Array

    Basically you need to organise your program better. If you know you need to add a Panel to your form and then PictureBoxes to the Panel then you should declare variables that you can use to access them, e.g.
    CSharp Code:
    1. private List<Panel> panels = new List<Panel>();
    2. private Dictionary<Panel, List<PictureBox>> pictureBoxesByPanel = new Dictionary<Panel, List<PictureBox>>();
    Now when you add a Panel to the form you add it to the List and to the Dictionary along with an empty List<PictureBox>. When you add a new PictureBox to a Panel you get the appropriate List<PictureBox> from the Dictionary by specifying the appropriate Panel, then add the new PictureBox. Now you can access every PictureBox by the Panel it's on via the Dictionary.

    Alternatively you could just access each Panel's Controls collection to access its child PictureBoxes, although the first solution is better.

    That said, instead of using Panels it would be far better to create your own UserControl that already encapsulated the functionality of the PictureBoxes, then add that to your form instead of a Panel.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [2.0] Control Array

    In any case here is a link from MSDN discussing how to create a control array. Not sure if its the one you appear to have seen earlier but it is a good tutorial.

    Creating Control Arrays in VB.NET and C#
    Last edited by Paul M; Jan 28th, 2008 at 08:38 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width