Results 1 to 12 of 12

Thread: [RESOLVED] Resource Files

  1. #1

    Thread Starter
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345

    [RESOLVED] Resource Files

    How can I store some images in a resource file at design time and fill a picture box with one at run time?

    I've searched a bit on the internet but have yet to return anything I can make sense out of :-/

    Thanks
    Last edited by TomGibbons; Dec 27th, 2003 at 09:05 AM.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Right click your project name in the solution explorer , then add new item or add existing item , then browse to your resource file (whether image , wav , icon) . When done , and the resource is there , change Build Action to embedded resource .

  3. #3

    Thread Starter
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    Thanks. Ok, I've put the JPGs in the resource file, how do I fill a picture box with one of them?

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    After you have added a resource image , use this :

    Note , you have to change filename to your actuall project name without spaces .
    Code:
    private void LoadResource()
    		{
    
    			string filename="YourProjectNameHere.ImageNameHere.jpg";
    			try 
    			{
    				pictureBox1.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(filename) );
    
    			}
    			catch (Exception x)
    			{
    				MessageBox.Show(x.Message);
    			}
    		}

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    BTW , you need to use :

    using System.Reflection;

    at the top .

  6. #6

    Thread Starter
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    Ok, I've not done it right. Could someone please explain this from the beginning (adding the jpegs)?

    Thank you :-/

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by TomGibbons
    Ok, I've not done it right. Could someone please explain this from the beginning (adding the jpegs)?
    Are you getting any specific error ? What part you couldn't do ?

  8. #8
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Here's a demo . If you followed the above steps , then do the code as in the demo .

  9. #9
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    opps
    Attached Files Attached Files

  10. #10

    Thread Starter
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    Ok, so how do you load the pictures into the resource file in the first place? I obviously didn't do that correctly

  11. #11
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Steps :
    1-Right click your project name in the solution explorer(not the solution name) , then select from the menu Add new item (if you are going to draw the image in the IDE ) or Add existing item (to add existing image or wav file on your harddrive )
    2-Then browse to your resource file (whether image , wav , icon) . You might need to change file type in the dropdown list in the Openfile dialog .
    3-When done , and the resource file is there , select your image , and change Build Action in properties window to embedded resource .
    4-Use the code I pasted above .

  12. #12

    Thread Starter
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    Thanks

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