Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error String cannot be converted to System.Drawing Image 1

Status
Not open for further replies.

WomanPro

Programmer
Nov 1, 2012
180
0
0
GR
Hello everyone

I have included 6 png files to my.Resources project and I am trying to load them into an image array at runtime.
But without effect, I am getting Error String cannot be converted to System.Drawing Image

Dim Pics(6) As Image
Dim str As String

For i = 0 To Pics.Length - 1
str = "my.Resources.Pic" & i + 1
[highlight #EF2929]Pics(i) = str[/highlight]
Next

I understand that I cannot assing a string value to an image type array. But I have to do it someway and I dodn't know the way to assign the value. The names resources' pictrures are Pic1, Pic2, Pic3, Pic4, Pic5, Pic6 and I wouldn't like to do it without a loop statement. Althoug everytime the value of each array element is different Pic1, Pic2 etc... (it's just different from the last character) what about if I had 50 images? I am a little bit confused. Please any help will be much appreciated.

Thanks everybody
in advanced.
 
You want something like this:

Code:
        Dim Pics(6) As Image
        Dim str As String

        For i = 0 To Pics.Length - 1

            Pics(i) = CType(My.Resources.ResourceManager.GetObject("Image" + i.ToString), System.Drawing.Image)

        Next()

The above will load Image0, Image1, etc. from the resource file.
Hope this helps.
 
Thank you so much RandyRiegel but if run it step by step each array element pics(i) is equal to nothing :(
 
worked as
pics(i) = My.Resources.ResourceManager.GetObject("Image" + i.ToString)

Thank you so much :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top