简体   繁体   English

使用VB代码在资源中添加图像文件

[英]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. 我想知道是否可以使用VB代码将本地文件添加为资源。 Its an image file . 它是一个图像文件。 Normally I go to Project -> Project1 Properties -> Resources -> Add Resource -> Add Existing File -> and select my executable. 通常我去Project-> Project1 Properties-> Resources-> Add Resource-> Add Existing File->并选择我的可执行文件。 I would like to do the above using Visual Basic code. 我想使用Visual Basic代码来完成上述操作。 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. 上一次我将资源添加到VB程序中时,我做的与您上面提到的相同,最近我去做同样的事情,发现我必须搜索位置,大多数重播此问题告诉您该怎么做,但是做了没有显示步骤,也没有显示屏幕,这有点令人困惑。 I hope the following helps. 希望以下内容对您有所帮助。

Visual Studio 2017: 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. 右键单击解决方案资源管理器窗口中的VB项目名称名称(“解决方案名称”(1个项目)不位于该名称正下方的那一行。选择属性,您将看到在我前面的项目选项屏幕打开默认情况下为以下屏幕截图左侧所示的应用程序标签。

视觉工作室屏幕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). 在解决方案资源管理器中,现在将显示资源选项卡,其中列出了您的文件,在我的示例中,我添加了两个声音文件bite.wav和moan.wav(对不起,不是图像文件)。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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