简体   繁体   中英

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. 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);

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