How do I put an icon on a form using code?
Thank you. 8 2256
If you have .ico file
this.Icon = new Icon(@"c:\myIcon.ico");
--
Shak
(Houston)
"Adrian" <aa@aa.aa> wrote in message
news:17***************************@freeler.nl... How do I put an icon on a form using code? Thank you.
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.
**********************************************
"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:ez**************@TK2MSFTNGP10.phx.gbl... If you have .ico file
this.Icon = new Icon(@"c:\myIcon.ico");
-- Shak (Houston)
"Adrian" <aa@aa.aa> wrote in message news:17***************************@freeler.nl... How do I put an icon on a form using code? Thank you.
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.MyC lass"));
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.
--
Shak
(Houston)
"Adrian" <aa@aa.aa> wrote in message
news:57***************************@freeler.nl... 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.
**********************************************
"Shakir Hussain" <sh**@fakedomain.com> wrote in message news:ez**************@TK2MSFTNGP10.phx.gbl... If you have .ico file
this.Icon = new Icon(@"c:\myIcon.ico");
-- Shak (Houston)
"Adrian" <aa@aa.aa> wrote in message news:17***************************@freeler.nl... How do I put an icon on a form using code? Thank you.
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.
"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... 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.MyC lass")); 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.
-- Shak (Houston)
"Adrian" <aa@aa.aa> wrote in message news:57***************************@freeler.nl... 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.
**********************************************
"Shakir Hussain" <sh**@fakedomain.com> wrote in message news:ez**************@TK2MSFTNGP10.phx.gbl... If you have .ico file
this.Icon = new Icon(@"c:\myIcon.ico");
-- Shak (Houston)
"Adrian" <aa@aa.aa> wrote in message news:17***************************@freeler.nl... > How do I put an icon on a form using code? > Thank you. > >
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.
--
Shak
(Houston)
"Adrian" <aa@aa.aa> wrote in message
news:e3**************************@freeler.nl... 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.
"Shakir Hussain" <sh**@fakedomain.com> wrote in message news:%2****************@tk2msftngp13.phx.gbl... 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.MyC lass")); 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.
-- Shak (Houston)
"Adrian" <aa@aa.aa> wrote in message news:57***************************@freeler.nl... 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.
**********************************************
"Shakir Hussain" <sh**@fakedomain.com> wrote in message news:ez**************@TK2MSFTNGP10.phx.gbl... > If you have .ico file > > this.Icon = new Icon(@"c:\myIcon.ico"); > > -- > Shak > (Houston) > > > "Adrian" <aa@aa.aa> wrote in message > news:17***************************@freeler.nl... > > How do I put an icon on a form using code? > > Thank you. > > > > > >
To add more on (2) if you have ControlBox property set to false in form, you
wont see the icon.
--
Shak
(Houston)
"Adrian" <aa@aa.aa> wrote in message
news:e3**************************@freeler.nl... 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.
"Shakir Hussain" <sh**@fakedomain.com> wrote in message news:%2****************@tk2msftngp13.phx.gbl... 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.MyC lass")); 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.
-- Shak (Houston)
"Adrian" <aa@aa.aa> wrote in message news:57***************************@freeler.nl... 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.
**********************************************
"Shakir Hussain" <sh**@fakedomain.com> wrote in message news:ez**************@TK2MSFTNGP10.phx.gbl... > If you have .ico file > > this.Icon = new Icon(@"c:\myIcon.ico"); > > -- > Shak > (Houston) > > > "Adrian" <aa@aa.aa> wrote in message > news:17***************************@freeler.nl... > > How do I put an icon on a form using code? > > Thank you. > > > > > >
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.
*********************************************
"Shakir Hussain" <sh**@nodomain.com> wrote in message
news:OH**************@TK2MSFTNGP09.phx.gbl... 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.
-- Shak (Houston)
"Adrian" <aa@aa.aa> wrote in message news:e3**************************@freeler.nl... 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.
"Shakir Hussain" <sh**@fakedomain.com> wrote in message news:%2****************@tk2msftngp13.phx.gbl... 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.MyC lass")); 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.
-- Shak (Houston)
"Adrian" <aa@aa.aa> wrote in message news:57***************************@freeler.nl... > 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. > > ********************************************** > > "Shakir Hussain" <sh**@fakedomain.com> wrote in message > news:ez**************@TK2MSFTNGP10.phx.gbl... > > If you have .ico file > > > > this.Icon = new Icon(@"c:\myIcon.ico"); > > > > -- > > Shak > > (Houston) > > > > > > "Adrian" <aa@aa.aa> wrote in message > > news:17***************************@freeler.nl... > > > How do I put an icon on a form using code? > > > Thank you. > > > > > > > > > > > >
Can you send me the project to sh***********@yahoo.com? I will investigate
wats going on. Zip the project if you can.
--
Shak
(Houston)
"Adrian" <aa@aa.aa> wrote in message
news:c4***************************@freeler.nl... 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. ********************************************* "Shakir Hussain" <sh**@nodomain.com> wrote in message news:OH**************@TK2MSFTNGP09.phx.gbl... 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.
-- Shak (Houston)
"Adrian" <aa@aa.aa> wrote in message news:e3**************************@freeler.nl... 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.
"Shakir Hussain" <sh**@fakedomain.com> wrote in message news:%2****************@tk2msftngp13.phx.gbl... > 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.MyC lass")); > 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. > > > -- > Shak > (Houston) > > > "Adrian" <aa@aa.aa> wrote in message > news:57***************************@freeler.nl... > > 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. > > > > ********************************************** > > > > "Shakir Hussain" <sh**@fakedomain.com> wrote in message > > news:ez**************@TK2MSFTNGP10.phx.gbl... > > > If you have .ico file > > > > > > this.Icon = new Icon(@"c:\myIcon.ico"); > > > > > > -- > > > Shak > > > (Houston) > > > > > > > > > "Adrian" <aa@aa.aa> wrote in message > > > news:17***************************@freeler.nl... > > > > How do I put an icon on a form using code? > > > > Thank you. > > > > > > > > > > > > > > > > > > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: WALDO |
last post by:
I have an interesting quandary.
I have developed a program in VB.Net to extract an icon resource from an
exe/dll or from an ico file and enumerate its formats (16x16,256
color;32x32,true...
|
by: Alice |
last post by:
Hi all
How can i change the status bar icon for my website
Or
The icon shown in user's Task Manager for the browser process fetching my website
Thanks in Advance
Alic
|
by: Allen Anderson |
last post by:
anyone know of some open source code floating around that does this?
I can do it with reshacker manually with the GUI but the cmd line
version of reshacker doesn't seem to work very well (at least...
|
by: Beenish Sahar Khan |
last post by:
I want to start my application so that its notify icon is added to the
system tray, i don't want to show any starting form. I want user to interact
through the notify icon...just like MSN. Is there...
|
by: Juan Romero |
last post by:
Hey guys,
I have an ImageList control that stores my icons. What I need to do is find
out if the icon at hand already exists in the ImageList so I dont enter it
twice. How can I do that?
...
|
by: randy1200 |
last post by:
I have a Windows application that previously had the company logo
"MyCompany.ico" added to the upper left-most corner. The company has since
issued a new version of "MyCompany.ico" that looks...
|
by: asif |
last post by:
When I add a USB key, system tray icon on Windows XP shows USB icon. It also
shows icon that can be used to "Safely Remove Hardware". I would like to use
this icon in one of my Visual C++...
|
by: Patrick Dugan |
last post by:
I am using VS2005 (vb) and I have a program that starts when Windows boots
up. Occasionally the icon that should appear in the system tray does not
show up. The program is still running in memory...
|
by: melon |
last post by:
This is a silly question. When I create a new project, Visual Studio
assigns a default icon (the one with some small colorful squares) to
the program. The icon is used in the title bar but not as...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |