简体   繁体   English

将文件路径设置为Visual Studio 2005中的Resources文件夹

[英]Set the file path to Resources folder in Visual Studio 2005

I am developing with VS2005 and I need to add an image to my tree view node.The image is located in the project in Resources folder. 我正在使用VS2005开发,需要将图像添加到树视图节点中。该图像位于资源文件夹中的项目中。 The following code is working fine and the image is displayed as expected. 下面的代码工作正常,并且图像按预期显示。

ImageList myImageList = new ImageList(); 
myImageList.Images.Add(Image.FromFile(@"E:\MyProject\HRProject\Attendence_Module\Attendence_Module\Resources\Employees.jpeg"));

Is there any way to give the path for the resource folder/file directly without mapping the complete path? 有没有办法直接提供资源文件夹/文件的路径而不映射完整路径? If I can will I be able to deploy the project with the same path in another computer? 如果可以,我是否可以使用相同的路径将项目部署到另一台计算机上?

I have added the image through the properties and then to resources and tried below code. 我已经通过属性添加了图像,然后将其添加到资源并尝试了以下代码。

myImageList.Images.Add(Image.FromFile(Properties.Resources.Employees));

But it generate two exceptions 但是它会产生两个例外

1)The best overloaded method match for System.Drawing.Image.FromFile(string)' has some invalid arguments    

2)Argument '1': cannot convert from 'System.Drawing.Bitmap' to 'string' 

First, did you set the image as an "Embedded Ressource" (Right-click your image => Properties...) 首先,您是否将图像设置为“嵌入式资源”(右键单击图像=>属性...)

Second, try loading your image like this : 其次,尝试像这样加载图像:

System.Reflection.Assembly thisExe = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.Stream file = 
    thisExe.GetManifestResourceStream("Attendence_Module.Employees.jpg");
myImageList.Images.Add(Image.FromStream(file));

试试myImageList.Images.Add(Properties.Resources.Employees);

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

相关问题 Visual Studio 文件夹文件路径 - Visual Studio Folder file path Visual Studio中的资源文件夹 - Resources folder in Visual Studio 将Visual Studio设置为创建SQL Server 2005支持的mdf文件 - Set Visual Studio to create mdf file that SQL Server 2005 supports Visual Studio Installer用于设置脚本文件的路径 - Visual Studio Installer with to set path of script file 将文件/资源​​移动到Visual Studio中的bin文件夹 - Move files/resources to the bin folder in Visual Studio 我可以将 windows (.bat ) 文件放在 Visual Studio C# 项目的资源文件夹中吗? - Can I put a windows (.bat ) file inside the resources folder of a Visual studio C# project? 试图播放“资源”文件夹中的.wav文件,但在那里,但Visual Studio表示不是! - trying to play .wav file which is in Resources folder, its there but visual studio sais it isn't! package中添加图片资源并部署到Visual Studio中时,图片资源的文件路径是什么? - What is the file path for image resources when you add them during package and deploy in Visual Studio? 在Visual Studio模板中更改项目文件夹路径 - Change Project Folder Path in Visual Studio Template 将Visual Studio资源文件放在“资源”以外的文件夹中? - Place Visual Studio resource files in a folder other than 'Resources'?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM