在 Windows 窗体应用程序中显示图片时要使用图片控件 ( PictureBox ),图片的设置方式与背景图片的设置方式相似。
图片控件中常用的属性如下表所示:
图片控件中图片的设置除了可以直接使用 ImageLocation 属性指定图片路径以外,
还可以通过 Image.FromFile 方法来设置。实现的代码如下:
图片控件的名称 .Image = Image. FromFile( 图像的路径 );
【实例】
实现图片交换。
Form1.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace PictureBoxForm { public partial class Form1 : Form { public Form1() { InitializeComponent(); } //窗体加载事件,设置图片空间中显示的图片 private void Form1_Load(object sender, EventArgs e) { //指定图片路径:图片控件的名称 .Image = Image. FromFile( 图像的路径 ); pictureBox1.Image = Image.FromFile(@"C:Users86186Desktop 1.jpg"/>
到此这篇关于C# PictureBox图片控件实现图片交换 的文章就介绍到这了,更多相关C# PictureBox 图片交换 内容请搜索179885.Com以前的文章或继续浏览下面的相关文章希望大家以后多多支持179885.Com!
- 上一篇:Unity学习之FSM有限状态机
- 下一篇:返回列表