前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C#中Imagelist控件

C#中Imagelist控件

作者头像
Twcat_tree
发布2022-11-30 20:07:49
1K0
发布2022-11-30 20:07:49
举报
文章被收录于专栏:二猫の家二猫の家

文章目录

一、使用编译器自动生成imagelist控件

1、首先拖入一个imagelist控件,其将在窗口下面分栏显示:

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2、插入一些图片:

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

3、系统自己生成的代码:

代码语言:javascript
复制
private void InitializeComponent()
       {
           this.components = new System.ComponentModel.Container();
           System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
           this.imageList1 = new System.Windows.Forms.ImageList(this.components);
           this.SuspendLayout();
           // 
           // imageList1
           // 
           this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
           this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
           this.imageList1.Images.SetKeyName(0, "10000.png");
           this.imageList1.Images.SetKeyName(1, "10001.png");
           this.imageList1.Images.SetKeyName(2, "10002.png");
           this.imageList1.Images.SetKeyName(3, "10003.png");
           this.imageList1.Images.SetKeyName(4, "10004.png");
           this.imageList1.Images.SetKeyName(5, "10005.png");
           this.imageList1.Images.SetKeyName(6, "10006.png");
           this.imageList1.Images.SetKeyName(7, "10007.png");
           this.imageList1.Images.SetKeyName(8, "10008.png");
           this.imageList1.Images.SetKeyName(9, "10009.png");
           this.imageList1.Images.SetKeyName(10, "10010.png");
           this.imageList1.Images.SetKeyName(11, "10011.png");
           this.imageList1.Images.SetKeyName(12, "10012.png");
           this.imageList1.Images.SetKeyName(13, "10013.png");
           this.imageList1.Images.SetKeyName(14, "10014.png");
           this.imageList1.Images.SetKeyName(15, "10015.png");
           this.imageList1.Images.SetKeyName(16, "10016.png");
           this.imageList1.Images.SetKeyName(17, "10017.png");
           this.imageList1.Images.SetKeyName(18, "10018.png");
           this.imageList1.Images.SetKeyName(19, "10019.png");
           this.imageList1.Images.SetKeyName(20, "10020.png");
           this.imageList1.Images.SetKeyName(21, "10021.png");
           this.imageList1.Images.SetKeyName(22, "10022.png");
           this.imageList1.Images.SetKeyName(23, "10023.png");
           this.imageList1.Images.SetKeyName(24, "10024.png");
           this.imageList1.Images.SetKeyName(25, "10025.png");
           this.imageList1.Images.SetKeyName(26, "10026.png");
           this.imageList1.Images.SetKeyName(27, "10027.png");
           this.imageList1.Images.SetKeyName(28, "10028.png");
           this.imageList1.Images.SetKeyName(29, "10029.png");
           this.imageList1.Images.SetKeyName(30, "10030.png");
           this.imageList1.Images.SetKeyName(31, "10031.png");
       }
   <span class="token preprocessor property">#<span class="token directive keyword">endregion</span></span>
   
   <span class="token keyword">private</span> <span class="token class-name">System<span class="token punctuation">.</span>Windows<span class="token punctuation">.</span>Forms<span class="token punctuation">.</span>ImageList</span> imageList1<span class="token punctuation">;</span>

}

二、动态创建imagelist控件

代码语言:javascript
复制
ImageList ImageList1 = new ImageList();
ImageList1.ImageSize = new Size(50,50);
//声明一个字符串,用来保存图片路径
string path;
for (int i = 0; i < 32; i++)
{
    if (i<10)
    {
        path = String.Concat("../../images/Bomb/1000", i.ToString(), ".png");
    }
    else
    {
        path = String.Concat("../../images/Bomb/100", i.ToString(), ".png");
    }
    imageList.Images.Add(Image.FromFile(path));
} 
用代码创建一个ImageList实例,规定图标大小50×50,接着使用ImageList.Images.Add方法加入Image对象,这边使用文件路径生成Image对象。
三、ImageList常用的方法大多在 ImageList.Images下
方法:

 ImageList.Images.Add:加入图像ImageList.Images.Clear: 清除图像ImageList.Images.Draw: 绘制指示的图像ImageList.Images.ContainsKey: 确定是否包含指定键的图像ImageList.Images.IndexOfKey:确定包含指定键的图像的序号ImageList.Images.RemoveAt:删除指定序号的图像ImageList.Images.RemoveByKey:删除指定键的图像ImageList.Images.SetKeyName:为指定序号的图像设置键名
属性:

 ImageList.Images.Count: 集合中包含的图像数ImageList.Images.Empty:集合中是否包含图像
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-07-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 文章目录
  • 一、使用编译器自动生成imagelist控件
  • 二、动态创建imagelist控件
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档