add icon to resource and use different sizes

P

Pieter

Hi,

In my VB.NET 2005 application I want to reuse several icons in different
sizes. My icons contains images of 16x16, 24x24, 32x32 and 48x48. The
problem is: I doesn't always use the right size: sometimes it resizes the
48x48 image to 16x16 instead of taking the 16x16 image. Is there a way to
specify which image of the icon has to be used?

Thansk a lot in advance,

Pieter
 
T

Tim Scott

Pieter,

The icon class has several constructors that take as arguments an
existing icon, and a preferred size:

Initializes a new instance of the Icon class and attempts to find a
version of the icon that matches the requested size.
[Visual Basic] Public Sub New(Icon, Size)

Initializes a new instance of the Icon class from a resource in the
specified assembly.
[Visual Basic] Public Sub New(Type, String)

Initializes a new instance of the Icon class and attempts to find a
version of the icon that matches the requested size.
[Visual Basic] Public Sub New(Icon, Integer, Integer)

You should be able to pass it the Icon that you loaded from your
resource, plus the desired size. MSDN docs say that is uses an icon of
the closest size. If you need a 48x48 and one isn't there, then it
might use the 32x32. If you need a 48x48, you will have to use
Graphics.DrawImage and stretch the image during drawing.

I hope this helps, please let me know how it turns out.

-- Tim
 
P

Pieter

Thanks for the info. Any idea how I can do this at designtime? For instance:
I have buttons, and the image-property must be set to the icon. I would like
to set these at designtime, but there doesn't seem to be a way to add
specify there the size?

Thanks a lot anyways!

Pieter
 
T

Tim

Pieter,

I have no ideas, sorry. I noticed that the PictureBox control will
always pick the right icon size (as you resize it in the designer) when
in StrechMode. But a Button control always seems to pick the largest
(or last?) image defined in the icon file.

-- Tim
 

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

Top