Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2014-04-28
3
Medium Priority
?
452 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 2000 total points
ID: 40028213
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
ID: 40028425
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
ID: 40028619
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Screencast - Getting to Know the Pipeline
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month10 days, 22 hours left to enroll

572 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