Using resource files

Using resource files

SRSDS
Advisor Advisor
721 Views
2 Replies
Message 1 of 3

Using resource files

SRSDS
Advisor
Advisor

This isn't AutoCAD specific but not sure where else to post it.

 

My app has uses a bunch of images that display in picture boxes.

Currently I have them in a folder that would be distributed with the app but I'd like to import them into the project itself.

 

I've worked out that I can access the imported image file using:

Global.MyApp.My.Resources.Resources.MyImage

 

MyImage being the resource filename

 

Is there a way I can make it a variable?

eg Dim MyImage as string = "Image" + "00"

PictureBox1.Image = Global.MyApp.My.Resources.Resources.MyImage

Accepted solutions (1)
722 Views
2 Replies
Replies (2)
Message 2 of 3

ActivistInvestor
Mentor
Mentor

@SRSDS wrote:

This isn't AutoCAD specific but not sure where else to post it.

 

My app has uses a bunch of images that display in picture boxes.

Currently I have them in a folder that would be distributed with the app but I'd like to import them into the project itself.

 

I've worked out that I can access the imported image file using:

Global.MyApp.My.Resources.Resources.MyImage

 

MyImage being the resource filename

 

Is there a way I can make it a variable?

eg Dim MyImage as string = "Image" + "00"

PictureBox1.Image = Global.MyApp.My.Resources.Resources.MyImage


The Resources class generated by the IDE should have a ResourceManager property.

 

You can call the ResourceManager's GetObject() method, passing in a string identifying the image, and cast the result to a Bitmap or whatever type the resource is.

The string you pass in should be the name of the property that returns the image (in your example, it would be "MyImage"):

 

Global.MyApp.My.Resources.Resources.GetObject("MyImage")

You can find out a lot by looking at the compiler-generated code that's normally hidden from you by VB.

0 Likes
Message 3 of 3

ActivistInvestor
Mentor
Mentor
Accepted solution

@Activist_Investor wrote:

The string you pass in should be the name of the property that returns the image (in your example, it would be "MyImage"):

 

Global.MyApp.My.Resources.Resources.GetObject("MyImage")

You can find out a lot by looking at the compiler-generated code that's normally hidden from you by VB.


Correction:

 

Global.MyApp.My.Resources.Resources.ResourceManager.GetObject("MyImage")