Icon question

  • Thread starter Thread starter Adrian
  • Start date Start date
Hi Shak,

Thank you. That works!

I have two questions if I may:

(1) How do you get around the problem of the client
changing the file in which the application should be installed?
(Yes, I can do an "if exists", but that doesn't solve the problem.)

(2) I have the icon showing in the "Properties" and in the prog
I have this.Icon = ((System.Drawing ... ("$this.icon))); This is
the same as I have in other applications. There I get an icon
showing up, here I don't. Might you please have an explanation?

Many thanks.

**********************************************
 
Adrian,

1. If you are worried about client modifying the icon file do this

a) add the icon file in the solution
b) go to the properties and set Build Action to "Embedded resource"
c) Rebuild your program.

your icon file will be now part of resource. To acess icon you can do
this

Assembly myAssembly =
Assembly.GetAssembly(Type.GetType("MyNameSpace.MyClass"));
Stream iconStream =
myAssembly.GetManifestResourceStream("MyNameSpace.myIcon.ico");
this.Icon = new Icon(icoStream);

2. When you select icon in the properties of form, you will see it
immediately in design mode. If thats not happening, there might be problem
in ur icon file or may be something else. Try loading the icon in
imagelist. It may give u a clue.
 
Hi Shak,

(1.a.) I wasn't worried about the client changing the icon; I was worried
about the client installing the application in a different directory so the
icon wouldn't be found. On second thought I realize that is a good way
to check whether the program is being properly installed. It is an
invoicing ("billing") program that has to work together with an accounting
program, which should have been installed already by the client.
(1.b.) I cannot find the Build Action in any properties box listing.

(2.) The icon is showing up ok in the properties box listing, hence
I was puzzled as to the cause of the icon not appearing on the
form when run. I have done no different in other programs where
there isn't an icon problem. This problem is arizing in the last two
applications I am working on.

Might you have any further suggestions?
Many thanks.
 
Adrain

1. After adding icon file into the solution, right click and select
properties. You will see build action which will have default value as
"Content" in properties. Change to embedded resource and follow the code i
gave you in the last post, to read the icon stream.

To explain with different example, when you create a c# application by
default, it creates "App.ico". Right click on that file and check the
properties. You will find "Build Action" in the property grid.

2. What is your Form BorderStyle? You wont see icon, for certain
borderstyles of the form. Try changing that property. I cannot think of any
other possibilities for not seeing the icon in ur Form.
 
To add more on (2) if you have ControlBox property set to false in form, you
wont see the icon.
 
Hi Shak,

Not out of the woods yet I fear.

(1.)
I have included your code.
I have put it in myForm_Load
No compile-time errors
No run-time errors
But no icon on the form.

(2.)
I have the border style set to FixedSingle
ControlBox is showing
In the properties list for myForm, the icon is displayed

For some funny reason one of the classes suddenly couldn't
be found either so I had to create a new class and give it the
code of the original class. That solved that one.

So I did the same with the icon file. That didn't help.

Is there something spooky going on here?

Adrian.
*********************************************
 
Can you send me the project to (e-mail address removed)? I will investigate
wats going on. Zip the project if you can.
 
Back
Top