Dynamic Resource Naming

  • Thread starter Thread starter TheLostLeaf
  • Start date Start date
T

TheLostLeaf

Hello,

Im a c# noob,

How do I Change this:

this.pictureBox[c].Image =
global::WindowsApplication1.Properties.Resources._00;
this.pictureBox[c].Image =
global::WindowsApplication1.Properties.Resources._01;
this.pictureBox[c].Image =
global::WindowsApplication1.Properties.Resources._02;

To This

for (int c = 0; c < pictureBox.Count; c++)
{
this.pictureBox[c].Image =
global::WindowsApplication1.Properties.Resources._0+c;
}

Thanks Again !
 
Hi,

If the WindowsApplication1.Properties.Resources property was created for you
by VS 2005 then the following code should work for you (Note: you probably
don't need the global alias qualifier either so don't use it unless you're
absolutely sure it's necessary):

for (int c = 0; c < pictureBox.Count; c++)
{
this.pictureBox[c].Image =
(Image) Properties.Resources.ResourceManager.GetObject("_0" + c);
}

BTW, you might want to choose a more descriptive naming convention than "_NN".
Try something like, "AnimalPictureNN", where NN is the number. I acknowledge
that might not be possible in your situation :)
 
Works Perfect !!! and saved me tons of code !

Much Thanks !

Dave said:
Hi,

If the WindowsApplication1.Properties.Resources property was created for you
by VS 2005 then the following code should work for you (Note: you probably
don't need the global alias qualifier either so don't use it unless you're
absolutely sure it's necessary):

for (int c = 0; c < pictureBox.Count; c++)
{
this.pictureBox[c].Image =
(Image) Properties.Resources.ResourceManager.GetObject("_0" + c);
}

BTW, you might want to choose a more descriptive naming convention than "_NN".
Try something like, "AnimalPictureNN", where NN is the number. I acknowledge
that might not be possible in your situation :)

--
Dave Sexton

TheLostLeaf said:
Hello,

Im a c# noob,

How do I Change this:

this.pictureBox[c].Image =
global::WindowsApplication1.Properties.Resources._00;
this.pictureBox[c].Image =
global::WindowsApplication1.Properties.Resources._01;
this.pictureBox[c].Image =
global::WindowsApplication1.Properties.Resources._02;

To This

for (int c = 0; c < pictureBox.Count; c++)
{
this.pictureBox[c].Image =
global::WindowsApplication1.Properties.Resources._0+c;
}

Thanks Again !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top