电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

C图片添加picturebox用法

C图片添加picturebox用法_第1页
1/7
C图片添加picturebox用法_第2页
2/7
C图片添加picturebox用法_第3页
3/7
C#关 于 picturebox和 imagelist的 用 法 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 TExt1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } int i; //系 统 当 前 有 一张默认图片 private void Form1_Load(object sender, EventArgs e) { if (imageList1.Images.Count >= 1) { pictureBox1.Image = imageList1.Images[0]; } i = -1; } //增 加 图 片 private void button1_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.InitialDirectory = "E:"; ofd.Filter = "图 像 |*.jpg"; ofd.RestoreDirectory = true; ofd.FilterIndex = 1; String fName; if (ofd.ShowDialog() == DialogResult.OK) { fName = ofd.FileName; Image myImage = Image.FromFile(fName, true); imageList1.Images.Add(myImage); } i++; pictureBox1.Image = imageList1.Images[i]; } //删 除 当 前 图 片 private void button2_Click(object sender, EventArgs e) { //图 片 数 量 大 于 1 if (imageList1.Images.Count >= 1&&i>=0) { imageList1.Images.RemoveAt(i); //i--; //判 断 图 片 是 否 为 空 if (imageList1.Images.Count == 0) { pictureBox1.Image = null; i = -1; } else { pictureBox1.Image = imageList1.Images[i]; } } //图 片 为 空 时 不显示 else { this.addTitle(); } } //显 示 下 一张图片 private void button3_Click(object sender, EventArgs e) { if (imageList1.Images.Count >= 1) { if (imageList1.Images.Count == 1) { MessageBox.Show("只有一张图片"); } i++; if (i > imageList1.Images.Count-1) { i = 0; } pictureBox1.Image = imageList1.Images[i]; } } //清 空 所 有 的 图 片 private void button4_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("确 定 清 空", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (DialogResult.OK == result) { imageList1.Images.Clear(); pictureBox1.Image = null; i = -1; this.addTitle(); } } //退 出 private void button5_Click(object sender, EventArgs e) { Application.Exit(); } //定 义 函 数 ——当 图 片 为空 时点击确 定 添加图 片 private void addTitle() { DialogResult sel = MessageBox.Show("图 片 为 空 ,请 选 择 一张 图片, 点 击 确 定 添 加 图片, 否 则 点 击 取 消 ! ", " 信 息 提 示 ", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (sel == DialogResult.OK) { OpenFileDialog ofd = new OpenFileDialog(); ofd.InitialDirectory = "E:"; ofd.Filter = "图 像|*.jpg"; ofd.RestoreDirectory = true; ofd.FilterIndex = 1; String fName; if (ofd.ShowDialog() == DialogResult.OK) { fName = ofd.FileName; Image myImage = Image.FromFile(fName, true); imageList1.Images.Add(myImage); } i++; try { pictureBox1.Image = imageList1.Images[i]; } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } }

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

C图片添加picturebox用法

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部