473,385 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

add icon to resource and use different sizes

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
Nov 21 '05 #1
4 3825
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

Nov 21 '05 #2
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" <ti******@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.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

Nov 21 '05 #3
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

Nov 21 '05 #4
Yes indeed, and this behaviour anoys me, hehe :-)

"Tim" <ti******@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.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

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ianruffell | last post by:
i've added an icon to an app i've written. when a shortcut is added to the desktop the icon colour is as expected. hwoever, when i run the app, both the taskbar icon and the icon on the app lose...
0
by: Haim Ashkenazi | last post by:
Hi I'm trying to build a binary with py2exe. I've used the method suggested in the py2exe wiki about adding icon resources to apps. it build ok on win2k, but when I try to build the same on...
2
by: Joe Wong | last post by:
Hi, I have encountered an error whenever I put the "icon_resources" line in my setup.py file: from distutils.core import setup import py2exe setup(
3
by: Grytpype-Thynne | last post by:
Is it possible to give a width to a floated div which is greater than the width of the image it contains? What I want to do is display some images which will be of different sizes so that they...
3
by: JR | last post by:
Take a look at TestStruct1 and TestStruct2. Clearly, the D2 part of the union is MUCH larger than the D1 portion. I would expect sizeof(TestStruct1)==sizeof(TestStruct2) but that is not the case...
1
by: Brian Henry | last post by:
I have an icon in my app as an embeded resource.. i am accessing it through the assemblies getmainfestresourcestream method of the assembly. The icon has a 32x32 and a 16x16 icon in the same icon...
0
by: Mythran | last post by:
I wrote some code that is supposed to enumerate through the specified file's win32 resources and return a string-array of all icon names. When it runs, it returns a string-array with a bunch of...
0
by: Steve McKewen | last post by:
Found it. You have to use the ToBitmap method in the Icon object, then that will convert to an Image. Image^ aImage = theIcon->ToBitmap(); Steve
4
TheSmileyCoder
by: TheSmileyCoder | last post by:
I need some simple 16x16 icons to use in a treeview on my form. Anyone know a good resource site for SIMPLE icons? Alot of the icons I have found are either so complex that they look like hell...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.