|
-
April 19th, 2009, 09:20 AM
#1
Icon class giving error
In my code, I'm trying to set an icon to a variable
Icon test = new Icon("systray.ico");
But this throws an exception and causes my program to crash if not handled (There should be no need to handle this). The file systray.ico is clearly included in my project and it even shows it on the solution explorer. Would there be something else I need to do to create a new icon variable?
[Edit]
I figured out that if I place the icon file on the same directory as the executable, then it works like a charm, but I need it to be called from the program itself. How do I accomplish this?
Last edited by l46kok; April 19th, 2009 at 09:32 AM.
-
April 19th, 2009, 11:52 AM
#2
Re: Icon class giving error
You can include the icon as a resource to your project.
In code you can do next:
Code:
Icon test = Properties.Resources.myIcon;
-
April 20th, 2009, 03:29 AM
#3
Re: Icon class giving error
Check if the file's "Copy to output directory" settings in files' properties in Solution Explorer. If you want to access it this way, it should be Copy...
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post. 
-
April 20th, 2009, 12:38 PM
#4
Re: Icon class giving error
 Originally Posted by l46kok
In my code, I'm trying to set an icon to a variable
Icon test = new Icon("systray.ico");
But this throws an exception and causes my program to crash if not handled (There should be no need to handle this)...
Also, any time that you are reading something from disk, you most certainly should handle any errors that may pop up.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|