简体   繁体   中英

Change the picture in picture box in C#

I am not sure what is my mistake but i am telling you it works before. I want to change the picture in picture box based on the user's choice.

The 1st picture i put is in the picture control box. which i just put the picture without doing the codes. then, when the system received the value that user chose, the picture will change to the 2nd image.

Code:

if (fheadValue == 101)
{                            
    Bitmap abc = (Bitmap)System.Drawing.Bitmap.FromFile
        ("C:\\Users\\HDAdmin\\Pictures\\humanbody\\MALE123\\images\\malebothandroid_01");
    pictureBox1.Image = abc;
}

Before this, i only using this code and it does change to the second picture. but now, its not working. I don't know what is wrong with my code.

then i tried using this code.

pictureBox1.Image = Image.FromFile("C:\\Users\\HDAdmin\\Pictures\\humanbody\\MALE123\\images\\malebothandroid_01");

But still, its not working. guys, please help me with this. it does work with the previous project but when i am applying the same method to the new project, it wont work. is there any careless mistake i made without noticing it..??

Just noticed, you haven't set the file extension of the image. you should add an extension. whether it's bmp,png,jpg..

Edit: Also call pictureBox1.Invalidate()

Edit2: As for the comments, there's no need to call Invalidate().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM