Getting image from resource file
-
Hi I am trying to get an image from a resource file into a picturebox. using the following code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Reflection; using System.Resources; namespace WindowsApplication16 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Assembly Massem; Image Mimage; Massem = this.GetType().Assembly; ResourceManager RM = new ResourceManager("WindowsApplication16.PH1", Massem); Mimage = (Image)RM.GetObject("MIS_1.png"); pictureBox1.Image = Mimage; } } }
the form has 1 button & 1 picture box. Resource name is : PH1.resx - inside there is the image file . the problem : When the code finsh i get a NULL image. Please advise. i used the explanation on the following MSDN: http://msdn2.microsoft.com/En-US/library/aa984408(VS.71).aspxHave a nice Day
-
Hi I am trying to get an image from a resource file into a picturebox. using the following code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Reflection; using System.Resources; namespace WindowsApplication16 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Assembly Massem; Image Mimage; Massem = this.GetType().Assembly; ResourceManager RM = new ResourceManager("WindowsApplication16.PH1", Massem); Mimage = (Image)RM.GetObject("MIS_1.png"); pictureBox1.Image = Mimage; } } }
the form has 1 button & 1 picture box. Resource name is : PH1.resx - inside there is the image file . the problem : When the code finsh i get a NULL image. Please advise. i used the explanation on the following MSDN: http://msdn2.microsoft.com/En-US/library/aa984408(VS.71).aspxHave a nice Day
Hi! You have to take care to use the correct name for the resource. Usually you have to prefix the object's filename with the namespace of your application (e.g. "WindowsApplication16.MIS_1.png" or whatever your namespace is).
Regards, mav -- Black holes are the places where God divided by 0...
-
Hi I am trying to get an image from a resource file into a picturebox. using the following code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Reflection; using System.Resources; namespace WindowsApplication16 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Assembly Massem; Image Mimage; Massem = this.GetType().Assembly; ResourceManager RM = new ResourceManager("WindowsApplication16.PH1", Massem); Mimage = (Image)RM.GetObject("MIS_1.png"); pictureBox1.Image = Mimage; } } }
the form has 1 button & 1 picture box. Resource name is : PH1.resx - inside there is the image file . the problem : When the code finsh i get a NULL image. Please advise. i used the explanation on the following MSDN: http://msdn2.microsoft.com/En-US/library/aa984408(VS.71).aspxHave a nice Day
Hi, I cant remember all the details, so this is what I do: - add the image file to the project, set it to "embedded resource" (you probably did that already) - use Designer to add some control (say picturebox) that consumes an image, and set it up to use your image - now look at the code Designer has generated for you, and copy/paste what you need - throw away what you no longer need Works the first time every time. :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }