生活随笔
收集整理的這篇文章主要介紹了
WinForm 显示图片PictureBox控件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在 Windows 窗體應用程序中顯示圖片時要使用圖片控件 ( PictureBox ),圖片的設置方式與背景圖片的設置方式相似。
圖片控件中常用的屬性如下表所示:
圖片導入實現代碼如下:
圖片控件的名稱
.Image
= Image
.FromFile(圖像的路徑
);
【實例】實現圖片交換
窗體界面:
代碼:
using System
;
using System
.Collections
.Generic
;
using System
.ComponentModel
;
using System
.Data
;
using System
.Drawing
;
using System
.Linq
;
using System
.Text
;
using System
.Threading
.Tasks
;
using System
.Windows
.Forms
;namespace WareHouse_WinForm
{public partial class ExchangePicture : Form{public ExchangePicture(){InitializeComponent();}private void ExchangePicture_Load(object sender
, EventArgs e
){this.pictureBox1
.Image
= global::WareHouse_WinForm
.Properties
.Resources
.background3
;pictureBox1
.SizeMode
= PictureBoxSizeMode
.StretchImage
;this.pictureBox2
.Image
= global::WareHouse_WinForm
.Properties
.Resources
.music1
;pictureBox2
.SizeMode
= PictureBoxSizeMode
.StretchImage
;}private void button1_Click(object sender
, EventArgs e
){PictureBox pictureBox
= new PictureBox();pictureBox
.Image
= pictureBox1
.Image
;pictureBox1
.Image
= pictureBox2
.Image
;pictureBox2
.Image
= pictureBox
.Image
;}}
}
總結
以上是生活随笔為你收集整理的WinForm 显示图片PictureBox控件的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。