How do I change a PictureBox's image?

十年热恋 提交于 2019-12-06 17:54:55

问题


I have a program in C# with a PictureBox object inside a Form. How do I change its picture? The pictures to chose from are in bin/Pics; they are jpeg in format, if that matters..


回答1:


Assign a new Image object to your PictureBox's Image property. To load an Image from a file, you may use the Image.FromFile method. In your particular case, assuming the current directory is one under bin, this should load the image bin/Pics/image1.jpg, for example:

pictureBox1.Image = Image.FromFile("../Pics/image1.jpg");

Additionally, if these images are static and to be used only as resources in your application, resources would be a much better fit than files.




回答2:


You can use the ImageLocation property of pictureBox1:

pictureBox1.ImageLocation = @"C:\Users\MSI\Desktop\MYAPP\Slider\Slider\bt1.jpg";


来源:https://stackoverflow.com/questions/11487901/how-do-i-change-a-pictureboxs-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!