C#图片添加picturebox用法

C#图片添加picturebox用法

ID:38580304

大小:32.00 KB

页数:4页

时间:2019-06-15

C#图片添加picturebox用法_第1页
C#图片添加picturebox用法_第2页
C#图片添加picturebox用法_第3页
C#图片添加picturebox用法_第4页
资源描述:

《C#图片添加picturebox用法》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、C#关于picturebox和imagelist的用法usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespaceTExt1{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}inti;//系统当前有一张默认图片privat

2、evoidForm1_Load(objectsender,EventArgse){if(imageList1.Images.Count>=1){pictureBox1.Image=imageList1.Images[0];}i=-1;}//增加图片privatevoidbutton1_Click(objectsender,EventArgse){OpenFileDialogofd=newOpenFileDialog();ofd.InitialDirectory="E:";ofd.Filter="图像

3、*.jpg";ofd.RestoreDirectory=true;ofd.FilterInde

4、x=1;StringfName;if(ofd.ShowDialog()==DialogResult.OK){fName=ofd.FileName;ImagemyImage=Image.FromFile(fName,true);imageList1.Images.Add(myImage);}i++;pictureBox1.Image=imageList1.Images[i];}//删除当前图片privatevoidbutton2_Click(objectsender,EventArgse){//图片数量大于1if(imageList1.Images.Count>=1&&i>=0){imageLi

5、st1.Images.RemoveAt(i);//i--;//判断图片是否为空if(imageList1.Images.Count==0){pictureBox1.Image=null;i=-1;}else{pictureBox1.Image=imageList1.Images[i];}}//图片为空时不显示else{this.addTitle();}}//显示下一张图片privatevoidbutton3_Click(objectsender,EventArgse){if(imageList1.Images.Count>=1){if(imageList1.Images.Count==1){M

6、essageBox.Show("只有一张图片");}i++;if(i>imageList1.Images.Count-1){i=0;}pictureBox1.Image=imageList1.Images[i];}}//清空所有的图片privatevoidbutton4_Click(objectsender,EventArgse){DialogResultresult=MessageBox.Show("确定清空???","提示信息",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);if(DialogResult.OK==result

7、){imageList1.Images.Clear();pictureBox1.Image=null;i=-1;this.addTitle();}}//退出privatevoidbutton5_Click(objectsender,EventArgse){Application.Exit();}//定义函数——当图片为空时点击确定添加图片privatevoidaddTitle(){DialogResultsel=MessageBox.Show("图片为空,请选择一张图片,点击确定添加图片,否则点击取消!","信息提示",MessageBoxButtons.OKCancel,MessageBox

8、Icon.Information);if(sel==DialogResult.OK){OpenFileDialogofd=newOpenFileDialog();ofd.InitialDirectory="E:";ofd.Filter="图像

9、*.jpg";ofd.RestoreDirectory=true;ofd.FilterIndex=1;StringfName;if(ofd.ShowDial

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。