CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2006
    Posts
    23

    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.

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    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;

  3. #3
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    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.

  4. #4
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Icon class giving error

    Quote Originally Posted by l46kok View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured