|
-
Jan 27th, 2008, 09:39 AM
#1
Thread Starter
Lively Member
[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.
-
Jan 27th, 2008, 11:35 AM
#2
Re: [2.0] Control Array
I think you need to rephrase your question. I dont really understand what you're trying to do.
-
Jan 27th, 2008, 05:17 PM
#3
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:
private List<Panel> panels = new List<Panel>(); 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.
-
Jan 28th, 2008, 08:35 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|