Solved

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

Posted on 2014-04-28
3
421 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Allow User To Arrange Columns At Datagridview 3 27
Crystal reports vb.net 2 41
vb.net and creating a class 5 17
VB.NET 2008 Winforms Signing 13 20
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…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

831 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