[英]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.