Loading a bitmap into an ImageList
-
I have a single bitmap image that is comprised of 16 images (like a toolbar bitmap). I use the following to load the image into my imagelist.
Image img = Image.FromFile("jsiml.bmp"); treeViewImageList.Images.AddStrip(img);
The problem is that the bitmap file must always be in the application folder. How can I add the bitmap as a resource and load the resource? TIA, Mark
-
I have a single bitmap image that is comprised of 16 images (like a toolbar bitmap). I use the following to load the image into my imagelist.
Image img = Image.FromFile("jsiml.bmp"); treeViewImageList.Images.AddStrip(img);
The problem is that the bitmap file must always be in the application folder. How can I add the bitmap as a resource and load the resource? TIA, Mark
Hi, Visual can show you how to do this. Example: add an icon to your app, look at what code gets generated. :)
Luc Pattyn [My Articles] [Forum Guidelines]
-
Hi, Visual can show you how to do this. Example: add an icon to your app, look at what code gets generated. :)
Luc Pattyn [My Articles] [Forum Guidelines]
-
I see what you mean. Anyway I used the following which works.
Image img = (Bitmap)JsLib.Properties.Resources.jsiml; treeViewImageList.Images.AddStrip(img);
I also had to change the "Build action" property for the bitmap to "Embedded resource". Mark
That's fine.
Luc Pattyn [My Articles] [Forum Guidelines]
-
I have a single bitmap image that is comprised of 16 images (like a toolbar bitmap). I use the following to load the image into my imagelist.
Image img = Image.FromFile("jsiml.bmp"); treeViewImageList.Images.AddStrip(img);
The problem is that the bitmap file must always be in the application folder. How can I add the bitmap as a resource and load the resource? TIA, Mark
To add an image as an embedded resource: 1)RightClick the project or folder in project in the Solution Explorer 2)Select Add an Existing Item 3)Locate the bitmap (I prefer clicking the arrow on the open button to choose the add as link. By doing this the latest bitmap will always be added in the build) 4)RightClick the bitmap in the project 5)In the properties window change the build action or where it says content and in the combo box make the value Embedded Resource To use the bitmap in your code: Bitmap b=new Bitmap(/*stream object*/this.GetType().Assembly.GetManifestResourceStream("{projectname}{.foldername if bitmap is in a folder}.{filename}); or something along those lines.
Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my homepage Oracle Studios[^]