1

I want to make a simple .exe application in vb.net. The application wont have an installation just pure run on .exe file .

Application has one form and two pictures. When i set the option on image to build action - compile

enter image description here

Unable to open module file 'C:\Users\t3cho\documents\visual studio 2013\Projects\Apps\Apps\Resources\power.png': System Error &H80041feb&   

Is there any other way to make an .exe file with images without installation or additional folders.

Anel
  • 63
  • 7
  • it might be how you are accessing Resources. – Ňɏssa Pøngjǣrdenlarp Jan 21 '15 at 15:30
  • You are trying to embed your picture as a resource, so try the Embedded Resource option for the file and open it using the built-in classes for resource reading. – PhillipH Jan 21 '15 at 15:30
  • [What are the various “Build action” settings in VS.NET project properties and what do they do?](http://stackoverflow.com/questions/145752/what-are-the-various-build-action-settings-in-vs-net-project-properties-and-wh) – Steve Jan 21 '15 at 15:31

2 Answers2

2

The easiest way to include images (and other types of resources) into the application is to right-click the project, go to the "Resources"-Tab and add the image there. You can change its name to e.g. MyEmbeddedImage and access it like this

Dim img As Image = Properties.Resources.MyEmbeddedImage

or

Dim img As Image = My.Resources.MyEmbeddedImage

This automatically sets the Build Action to None.

Note: This approach is type-safe and you will get errors at compile time, if the image is missing.

See: My.Resources Object and How to: Add or Remove Resources


If you still want to embed the image "manually", you must set the Build Action to Embedded Resource and access it as @Icemanind describes.

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
0

Yes. It's called embedded resources. Set your image's Build Action to Embedded Resource. You can then get the image at runtime like so:

Try
    _assembly = [Assembly].GetExecutingAssembly()
    _imageStream =  _assembly.GetManifestResourceStream("MyNameSpace.MyImage.png")
    ' Do something with _imageStream
Catch ex As Exception
    ' Resource not found or something went wrong
End Try
Icemanind
  • 47,519
  • 50
  • 171
  • 296