Windows应用程序高级控件之ImageList
来源:互联网 发布:医院预约管理系统php 编辑:程序博客网 时间:2024/05/01 13:12
1.ImageList控件
(1)用途:
用于存储图像资源,并在控件上显示出来。
(2)主要属性:Images
包含关联控件将要使用的图片,每个单独的图像可以通过其索引值或键值来访问。
所有图像以同样的大小显示,大小由ImageSize属性设置。较大的图片将缩小至适当的尺寸。
(3)Images属性的Add方法
用来将指定的图片加到ImageList控件中。
(4)实例部分重要代码
private void Form1_Load(object sender, EventArgs e) { //设置要加载的第一张图片的路径 string Path = "01.jpg"; //设置要加载的第二张图片的路径 string Path2 = "02.jpg"; Image Mimg = Image.FromFile(Path, true);//创建一个Image对象 imageList1.Images.Add(Mimg);//使用Images属性的Add方法向控件中添加图像 Image Mimg2 = Image.FromFile(Path2, true);//创建一个Image对象 imageList1.Images.Add(Mimg2);//使用Images属性的Add方法向控件中添加图像 imageList1.ImageSize = new Size(200, 165);//设置显示图片的大小 pictureBox1.Width = 200;//设置pictureBox1控件的宽 pictureBox1.Height = 165;//设置pictureBox1控件的高 } private void button1_Click(object sender, EventArgs e) { //设置pictureBox1的图像索引是imageList1控件索引为0的图片 pictureBox1.Image = imageList1.Images[0]; } private void button2_Click(object sender, EventArgs e) { //设置pictureBox1的图像索引是imageList1控件索引为1的图片 pictureBox1.Image = imageList1.Images[1]; }
运行截图:
我们知道怎么向ImageList控件里加图片,那怎么移除图像呢?这边注意不是删除原图片哦,只是从ImageList控件里移除而已。
方法一:RemoveAt方法移除单个图像
public void RemoveAt(int index)
参数index表示要移除的图像的索引
方法二:Clear方法清除图像列表中的所有图像
public void Clear()
移除实例代码:
private void button1_Click(object sender, EventArgs e) { pictureBox1.Width = 200; pictureBox1.Height = 165; string Path = "01.jpg"; Image img = Image.FromFile(Path, true); imageList1.Images.Add(img); imageList1.ImageSize = new Size(200, 165); pictureBox1.Image = imageList1.Images[0]; } private void button2_Click(object sender, EventArgs e) { imageList1.Images.RemoveAt(0); pictureBox1.Image = null; }
当然这边只是用的RemoveAt()方法,也可以直接imageList1.Clear()直接移除所有图像。
运行截图:
点击加载图像按钮
点击移除图像按钮
0 0
- Windows应用程序高级控件之ImageList
- Windows应用程序高级控件之ListView控件
- Windows应用程序高级控件之TreeView
- Windows应用程序高级控件之月历控件--MonthCalendar控件
- C#控件之ImageList
- Windows应用程序高级控件之日期控件-DateTimePicker
- Windows应用程序高级控件之ErrorProvider,HelpProvider,Timer和ProgressBar
- 第11章 Windows应用程序高级控件
- Windows 应用程序高级控件(C#)
- ImageList 控件
- C#成魔之路<1>Windows 应用程序高级控件(1)
- C#成魔之路<2>Windows 应用程序高级控件(2)
- C#windows应用程序之控件之旅
- ImageList控件的学习
- 存储图像控件ImageList
- ImageList控件(3)
- ImageList存储图像控件
- windows窗体高级控件
- java实现Img与PDF相互转换
- memset()函数的应用
- A*算法(转)
- SWF 文件不能访问本地资源
- 利用Robot Framework和Python wrapper of Android uiautomator的Android测试自动化
- Windows应用程序高级控件之ImageList
- 算法导论堆排序java实现
- VS2010 无法打开包括文件:“iostream.h”: No such file or directory
- 清除浮动
- FIREFOX和CHROME浏览器下PercentLoaded()不能使用的解决方案
- windows中修改catalina.sh上传到linux执行报错This file is needed to run this program
- Qt5.3里使用X264库将y4m文件进行压缩
- MSOCache文件夹能否删除?
- jquery获取checkbox 的值