Passing the name of a component and use it to do something to that component

  • Thread starter Thread starter Ivan Sammut
  • Start date Start date
I

Ivan Sammut

Hi,

I have an form with 64 picture boxes named pic1 ... pic64.

Then I have a procedure which create a bitmap filled with red and then I
place it in the PictureContainer. Now I would like to know if it is possible
to pass to this procedure name of the picture box in which to place the
bitmap

Example (this does not work)
string sTxt = "pic1";
Bitmap bmp1 = new Bitmap(32,32);
(PictureBox)sTxt.Image=bmp1; <<Error Here

Any idea if it is possible to achieve this.

Regards
Ivan Sammut
 
hi,

Each control has a Name property, you can search the Controls collection
for the correct Name value.

foreach( Control control in Controls)
if ( control.Name == theName )
( (PictureBox)control).Image = bmp1;


cheers,
 
Back
Top