Home All Groups Group Topic Archive Search About

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

Author
25 Mar 2005 12:28 PM
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

Author
25 Mar 2005 1:26 PM
Ignacio Machin ( .NET/ C# MVP )
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Show quote
"Ivan Sammut" <samm***@hotmail.com> wrote in message
news:uj7HFYTMFHA.2704@TK2MSFTNGP15.phx.gbl...
> 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
>
>
>

AddThis Social Bookmark Button