Solved

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

Posted on 2014-04-28
3
426 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.

732 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