|
-
Dec 26th, 2003, 02:04 PM
#1
Thread Starter
Frenzied Member
[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.
-
Dec 26th, 2003, 04:00 PM
#2
Sleep mode
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 .
-
Dec 26th, 2003, 04:03 PM
#3
Thread Starter
Frenzied Member
Thanks. Ok, I've put the JPGs in the resource file, how do I fill a picture box with one of them?
-
Dec 26th, 2003, 04:56 PM
#4
Sleep mode
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);
}
}
-
Dec 26th, 2003, 04:57 PM
#5
Sleep mode
BTW , you need to use :
using System.Reflection;
at the top .
-
Dec 27th, 2003, 07:46 AM
#6
Thread Starter
Frenzied Member
Ok, I've not done it right. Could someone please explain this from the beginning (adding the jpegs)?
Thank you :-/
-
Dec 27th, 2003, 07:53 AM
#7
Sleep mode
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 ?
-
Dec 27th, 2003, 08:10 AM
#8
Sleep mode
Here's a demo . If you followed the above steps , then do the code as in the demo .
-
Dec 27th, 2003, 08:11 AM
#9
-
Dec 27th, 2003, 08:48 AM
#10
Thread Starter
Frenzied Member
Ok, so how do you load the pictures into the resource file in the first place? I obviously didn't do that correctly
-
Dec 27th, 2003, 08:56 AM
#11
Sleep mode
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 .
-
Dec 27th, 2003, 09:04 AM
#12
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|