Reputation: 305
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'
Upvotes: 0
Views: 1174
Reputation: 1367
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));
Upvotes: 1