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 2 buttons, labeled them and added 2 picture boxes then I looked it up. I found, I should in every button write the code like this.
pictureBox1.Image = Image.FromFile(Properties.Resources.Head);
But it give me error says that I cannot convert from system.drawing.bitmap
to string
note: I've added the pictures in the resources
CodePudding user response:
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