Results 1 to 4 of 4

Thread: Reading from embedded resources

  1. #1

    Thread Starter
    Lively Member sk8er_boi's Avatar
    Join Date
    Jun 2010
    Posts
    65

    Question Reading from embedded resources

    hi all,

    i have added 3 .png files [done.png, failed.png, busy.png] to my project & changed them to "embedded resource" [from this wht i understand is that they will be integrated within the exe hence eliminating the dependency on the actual location it is stored]

    i have 1 picturebox on my form whose image i have to change as per the output of something else

    this is wht my code looks like :

    Code:
    If text1.text = "Done" then
    picturebox1.image = my.resources.done.png
    end if
    
    If text1.text = "Failed" then
    picturebox1.image = my.resources.failed.png
    end if
    but it gives me error during run time.. am i using the right code ? or is there an alternate method for this ?

  2. #2
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Reading from embedded resources

    Just leave off the .png. The resource names are built automatically from the file name less the extension, although you can change them to anything you like.
    BB

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Reading from embedded resources

    If you want to use My.Resources then you can't add the files to the Solution Explorer directly. You have to add them to the Resources page of the project properties. You have two choices:

    1. Delete your files from the Solution Explorer. Open the project properties to the Resources page. Add your files. Now you can use My.Resources in code.

    2. Change your code to use the ResourceManager class to get your resources by name.

    I'd go with the first option.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Lively Member sk8er_boi's Avatar
    Join Date
    Jun 2010
    Posts
    65

    Resolved Re: Reading from embedded resources

    Quote Originally Posted by jmcilhinney View Post
    If you want to use My.Resources then you can't add the files to the Solution Explorer directly. You have to add them to the Resources page of the project properties. You have two choices:

    1. Delete your files from the Solution Explorer. Open the project properties to the Resources page. Add your files. Now you can use My.Resources in code.

    2. Change your code to use the ResourceManager class to get your resources by name.

    I'd go with the first option.

    this worked (option1) !!! thx a ton

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