如何更改PictureBox的图像? [英] How do I change a PictureBox's image?

查看:128
本文介绍了如何更改PictureBox的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中有一个程序,在表单中有一个 PictureBox 对象。我该如何改变它的图片?可供选择的图片在bin / Pics中;它们是jpeg的格式,如果这很重要..

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..

推荐答案

分配一个新的 图片 对象 PictureBox 图像属性。要从文件加载 Image ,您可以使用 Image.FromFile 方法。在您的特定情况下,假设当前目录是 bin 下的目录,这应该加载图像 bin / Pics / image1.jpg ,例如:

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.

这篇关于如何更改PictureBox的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆