imagelist and bitmaps

  • Thread starter Thread starter Sam
  • Start date Start date
S

Sam

Hi,
I've added two bitmaps to my project. Now I would like to create an
imagelist (in the code) and add those two images to it (so no path,
just the name). And I want those images to be compiled in the .dll.
This is a user control, so this why I want them to be embedded within
the dll.

Thx
 
You don't need to add them to your project. You can either add an imagelist
control to your form and add the images in the property editor of the
control; doing this will make them resources. Or you can right click on the
bmp file and compile it as an embedded resource - then get them at run-time.
I would recommend the former as it's a bit easier than flapping around with
embedded resources manually.
 
Set the bitmaps build action to embedded resource and try this code to get
the image and load it in the imagelist:

Dim p As System.Reflection.Assembly
p = System.Reflection.Assembly.GetExecutingAssembly()
Dim img As New Bitmap(p.GetManifestResourceStream(Me.GetType(),
"envelop.jpg"))
ImageList1.Images.Add(img)

hth Greetz Peter
 
Hi, I know it does, but I would also go for the first suggestion Robin made,
becauses it's more clear then getting things from the assembly

Greetz Peter
 
No, I can't just drag n drop an imagelist in my form : I don't have a
form! It's a user control inherited from Panel. Therefore I have to
hard-code everything myself. Your method is a better choice in that
case.

Thx
 
You should be able to drag/drop an image list onto a user control - unless -
ahh, I see. Was there a specific reason you derived from panel?
 
No, I can't just drag n drop an imagelist in my form : I don't have a
form! It's a user control inherited from Panel. Therefore I have to
hard-code everything myself. Your method is a better choice in that
case.

Thx
 
it's not even a user control, it's more like an inherited control. I've
just created my own personified docking panel. So in design mode there
is nothing to see.
 
Just out of interest - I've learnt to gather all my images in one place and
dynamically load them into a global singleton - similar to the way Peter
suggests. The reason for this is because often many components share
images/icons and it's helps keep .exe size down if you share instances
(provided they don't get edited of course), rather than adding them at each
location. Same for toolbar icons, which often are used in many
components/places.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top