Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

im trying to make a button in c# windows form app that when i click on it it show a picture i want

so i’ve this assignment that im supposed to do a which is a c# wfa that contains 2 buttons one labeled as show head and another for show tail and when i click on of them it should shows the picture of it

i’ve added the 2 button labeled them and added 2 pictures box then i looked it up i found i shoud in every button right a code like this

pictureBox1.Image = Image.FromFile(Properties.Resources.Head);

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

but it give me error says that i cannot convert from system.drawing.bitmap to string
note: i’ve added the pictures in the resoureces

>Solution :

Image.FromFile method accepts a file path in string form. while you an image bitmap itself in resource (and not a location of the image present in local/remote directory)

refer this: https://docs.microsoft.com/en-us/dotnet/api/system.drawing.image.fromfile?view=dotnet-plat-ext-6.0

So for solution part, instead of

pictureBox1.Image = Image.FromFile(Properties.Resources.Head);

try this

pictureBox1.Image = Properties.Resources.Head
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading