Solved

Visual Studio 2008 form ICON cannot be accessed as a common resource

Posted on 2014-04-28
3
419 Views
Last Modified: 2014-04-28
Hi,

I am working on a corporate image update for our applications.  The old ico file was a very old one and it was only 1KB in size (was only one size at 32x32).  I was given a much more modern ico file that supports 6 different resolutions.  This new ico file is 362KB in size.  After incorporating this new ico file into my project, (changing it in Project Properties->Application->Icon (which seems to be a pointless exercise)) and also changing it in every form I have (about 15), my compiled exe size grew from about 700K to 6M, almost a 10 fold increase in size.

It seems that the way Visual Studio 2008 references an ico file is to incorporate a copy of the whole image right into each and every form in the project instead of referencing one common ico for the whole project.

Is there a work around for this to simply use one single ico reference for all forms.
0
Comment
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
Comment Utility
Insert the icon as a resource in the application itself, and set it to the forms in the Form_Load event.

To insert it in the application resources, open the project's Properties window and it's Resources tab.

Select Icons in the upper left corner of the window.

Then, under Add Resource, go to Add Existing File to select your icon.

A right click will enable you to give if a better name is the one coming from the file is not very good. That name will be used in code to reference the icon.

Now, in the Form_Load event of all your forms, add a line like the following:

Me.Icon=My.Resources.YourIconName

Et voilà
0
 

Author Closing Comment

by:RobertFromSecretWeapons
Comment Utility
That is very clever.  WOW. I guess I can't think out of the box today. Works great.
The only remaining issue I will have to test for is to see if a proper desktop icon is found during the creation of a desktop shortcut icon rather than the little placeholder icon that all the forms now have.

I assume this issue should be properly addressed by the application icon that gets initialized in the project->project properties->application->Icon setting for the windows form project.
0
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
Unfortunately, I do not know a way to set a resource to the application. I have searched for ways to do it both ways. Either set the forms icon to the one defined for the application, or set the application icon to the resource. Unfortunately, I never found an answer. The application icon seems to be defined in the application manifest instead of the resources.

So as far as I know, the application icon must be defined separately from the resource.

What you can do however if you want to minimize space, is to make a copy of your icon file, open the copy in Visual Studio, and delete the resolutions that are not needed for a desktop icon. The different resolutions available are listed at the left side of the editor, and you can delete those you do not need. Then reference that copy for the application icon.

On the other side, if you will not be using the icons in the resource for anything else than the forms icon, you might want to make a copy of the file, remove the resolutions that are not used for the forms, and use that instead in your resources.

You might have to make a few tests in different environments to see which resolutions are never used for the desktop icon and which are never used for the forms icons.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now