简体   繁体   中英

Add a image file in resources using VB code

I would like to know if there is any way to add a local file as resource using VB code. Its an image file . Normally I go to Project -> Project1 Properties -> Resources -> Add Resource -> Add Existing File -> and select my executable. I would like to do the above using Visual Basic code. Does anybody have any idea?

Last time I added a resource into my VB program I did the same as you have mentioned above, recently I went to do the same thing and found I had to search for the location and most replays to this question told you what to do but did not show the steps nor the screen which was kinda confusing. I hope the following helps.

Visual Studio 2017:

  1. Right click in the solution explorer window on the VB project name name (Not where is says Solution 'Solution name' (1 project) the line just under that one. Select properties and you will see the project options screen open in front of you mine defaulted to the application tab shown on the left in the screen shot below.

视觉工作室屏幕1

  1. Select the resources option on the left hand side of the screen, you now have options to add resource files to your executable, you can select the following types (Strings, images, icons, audio, files, other) . Note I read there is a size limit for individual files but it is possible to have multiple small files added.

Add your file. In the solution explorer a resources tab will now be visible with your file listed, in my example I added two sound files bite.wav and moan.wav (sorry not an image file). These sound files were compiled into my executable and I executed the sounds in the program with the following:

My.Computer.Audio.Play(My.Resources.Moan, AudioPlayMode.Background) 'Play audio file in background do not halt program 

Your resource should now be able to be seen if you enter 'My.Resources.'

屏幕2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM