Windows Develop Bookmark and Share   
 index > Windows Forms General > How to access each multi objects property?
 

How to access each multi objects property?

Compiler: VC++ 2005.

Application: Win Forms

Subject: How to access each multi objects property?

I have multiple picturebox s in a form, i.e. pict01, pict02, �pict19.

And, I need to assign each file to its image property (i.e. pict01->Image).

Instead of writing

pict01->Image = "";

pict02->Image = "";

pict03->Image = "";

pict04->Image = "";

pict05->Image = "";

pict06->Image = "";

pict07->Image = "";

pict08->Image = "";

pict09->Image = "";

pict10->Image = "";

pict11->Image = "";

pict12->Image = "";

pict13->Image = "";

pict14->Image = "";

pict15->Image = "";

pict16->Image = "";

pict17->Image = "";

pict18->Image = "";

pict19->Image = "";

what shoud I write?

thank you

stn  Wednesday, June 06, 2007 8:54 AM

iterate thru the Controls collection of your form for PictureBox instances & set its Image proeprty.

in c# you would use a foreach.

foreach (PictureBox pictureBox in this.Controls) {
pictureBox.Image = Image.FromFile("filename");
}
a.Binny  Wednesday, June 06, 2007 9:13 AM

iterate thru the Controls collection of your form for PictureBox instances & set its Image proeprty.

in c# you would use a foreach.

foreach (PictureBox pictureBox in this.Controls) {
pictureBox.Image = Image.FromFile("filename");
}
a.Binny  Wednesday, June 06, 2007 9:13 AM

Your method is one of them. However, i dont want to access all picture box.

And, some of picturebox 's name has number in it (i.e. pict01, pict02, etc).

And, the images files also have numbers (i.e image01.jpg, image02.jpg, etc).

To display them, I have imposed certain rules on it (i.e. pict01 = image03, etc).

At another time, it may be that (i.e. pict01 = image02, etc).

Therefore, i need to access each control by its name.

Any other way to do it?

thanks in advance.

stn  Friday, June 08, 2007 9:13 AM

You can use google to search for other answers

Custom Search

More Threads

• How to set start form
• Email Attach using XmlHttp causes problems
• How to use DDBLTFX?
• Hide a column in a DataGidView on a TabControl TabPage
• Updating UI with Threads.
• Block applications for some accounts.
• BringtoFront issue
• Determine if a Form has been created...
• How do I bind data from a table adapter to controls on a WinForm?
• Convert DataSet to Excel Sheet