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

Re: add icon to resource and use different sizes by Tim

Tim
Wed Oct 19 11:28:37 CDT 2005

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


Re: add icon to resource and use different sizes by Pieter

Pieter
Thu Oct 20 02:35:22 CDT 2005

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

"Tim Scott" <timscott@gmail.com> wrote in message
news:1129739317.343818.65620@g44g2000cwa.googlegroups.com...
> 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
>



Re: add icon to resource and use different sizes by Tim

Tim
Thu Oct 27 00:03:16 CDT 2005

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


Re: add icon to resource and use different sizes by Pieter

Pieter
Thu Oct 27 03:17:53 CDT 2005

Yes indeed, and this behaviour anoys me, hehe :-)

"Tim" <timscott@gmail.com> wrote in message
news:1130389396.741993.266270@g44g2000cwa.googlegroups.com...
> 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
>