Reference embedded resource 
Author Message
 Reference embedded resource

How do I reference a resource I have embedded in a application?

I have an image (image1.jpg) that I need to set as the background for a
form.  I have added the image to the project and set the build action to
embedded resource. However, I can't figure out how to pull that out to use
it as my background.

Thanks for the help!!



Tue, 26 Apr 2005 22:55:45 GMT  
 Reference embedded resource

Quote:
> How do I reference a resource I have embedded in a application?

> I have an image (image1.jpg) that I need to set as the
> background for a form.  I have added the image to the project
> and set the build action to embedded resource. However, I can't
> figure out how to pull that out to use it as my background.

imports system.reflection
'...

Dim img As Image
Dim stream As IO.Stream
Dim assy As [Assembly] = [Assembly].GetExecutingAssembly

stream = assy.GetManifestResourceStream("myapp.image1.jpg")
img = Image.FromStream(stream)
stream.Close()

Replace "myapp" by the root namespace of your project.

Armin



Tue, 26 Apr 2005 23:29:54 GMT  
 Reference embedded resource
Thank you for the quick response!!! That worked perfectly.


Quote:

> > How do I reference a resource I have embedded in a application?

> > I have an image (image1.jpg) that I need to set as the
> > background for a form.  I have added the image to the project
> > and set the build action to embedded resource. However, I can't
> > figure out how to pull that out to use it as my background.

> imports system.reflection
> '...

> Dim img As Image
> Dim stream As IO.Stream
> Dim assy As [Assembly] = [Assembly].GetExecutingAssembly

> stream = assy.GetManifestResourceStream("myapp.image1.jpg")
> img = Image.FromStream(stream)
> stream.Close()

> Replace "myapp" by the root namespace of your project.

> Armin



Tue, 26 Apr 2005 23:58:54 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Playing WAV from Embedded Resource

2. embedding resources

3. Help with loading embedded resources

4. How to access embedded resources?

5. Embed sounds into VB resources

6. Embedded Resource (.ico or .bmp) and ListView

7. ImageList and an embedded resource file.

8. Using "embedded resources"

9. Web control using embedded resource

10. GIFs as Embedded Resources

11. Embedded Resources in VB

12. How does one display embedded AVI resources?

 

 
Powered by phpBB® Forum Software