picturebox's image

T

TS

how do i tell where i got the image for a picturebox control? I need to
locate its file for use in my web app.
 
H

Herfried K. Wagner [MVP]

* "TS said:
how do i tell where i got the image for a picturebox control? I need to
locate its file for use in my web app.

This information is not stored for the picturebox's 'Image' property.
 
J

Jeffrey Tan[MSFT]

Hi TS,

Based on my understanding, you want to re-use the image in one assembly in
another application.

Actually, when you specify the a picture for the PictureBox.Image property
in Property browser, the picture will be embed in the Form class as
resource, it will contain no path information about the picture on the disk.

For your issue, I think you may retrieve the image resource directly from
the assembly and reuse for your second picturebox, code like this:
private void button1_Click(object sender, System.EventArgs e)
{
Assembly ass=Assembly.LoadFrom(@"your first assembly path");
Type t=ass.GetType("accesstest.Form1");
//GetType("applicationname.classname")

System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(t);
this.pictureBox1.Image =
((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
//resource name
}
=========================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
T

TS

well i actually need to give someone the image file. Do you think i should
do what you have here, and then save it to a file?
 
J

Jeffrey Tan[MSFT]

Hi TS,

Thanks for your feedback.

Yes, because once you set an image for the picturebox in property browser,
this image will be embeded in the assembly as resource, it will has no
relation with the picture on the disk, and it makes no sense for the
resource to store the image path information. Also, the user may have
deleted , modified or moved the original image on the disk.

So for your issue, I think you may retrieve the image resource from the
assembly and save it again to the disk. Like this:
private void button1_Click(object sender, System.EventArgs e)
{
Assembly ass=Assembly.LoadFrom(@"You picturebox assembly");
string[] res_name_arr=ass.GetManifestResourceNames();
foreach(string str in res_name_arr)
{
Console.WriteLine(str);
}
Type t=ass.GetType("accesstest.Form1");

System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(t);
System.Drawing.Image
img=(System.Drawing.Image)(resources.GetObject("pictureBox1.Image"));
img.Save(@"D:\\savedpic.bmp");
}
=========================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi TS,

Thanks for your feedback.

I am glad my reply makes sense to you, if you need further help, please
feel free to tell me, I will help you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top