再问imageList.TransparentColor
ImageList 类属性:TransparentColor 获取或设置被视为透明的颜色上面这幅图,我为了让圆周围的白色称为透明,
首先,用QQ的截图工具,查看周围白色的参数,为255,255,255
然后,设置 imageList1.TransparentColor = Color.FromArgb(255, 255, 255);
但是,为什么运行后,白色还是存在呢,没有透明呢? --------------------编程问答-------------------- 等待答案 --------------------编程问答-------------------- ImageList做的透明处理是在Load或设定图像的时候处理:
imageList.Images.Add(image);
imageList.Images[i]=image;
对于已经存在于list中的图像,设置了TransparentColor也不会起什么作用,TransparentColor只会影响到后续添加的图像
不过你的要求可以通过下面代码实现
int index = button2.ImageIndex;
imageList1.Images[index] = imageList1.Images[index];
button2.Refresh();
--------------------编程问答--------------------
请问:
1:Refresh:重绘,这里的重绘是不是和Paint一样,重绘,顾名思义,就是画吧,是不是?可是button2中没有GDI+画的图形啊?
2:你写的:imageList1.Images[index] = imageList1.Images[index];是什么意思,等号两边的内容是一样的
--------------------编程问答-------------------- 等待答案 --------------------编程问答-------------------- imageList1.Images[index] = imageList1.Images[index];
你应该知道C#的属性和索引器吧
这个特性,导致赋值语句可能没你想象的那么简单,因为赋值可能呢会触发属性的set方法
imageList1.Images是一个 ImageList.ImageCollection对象
这个对象很可能是这样实现索引器的
class ImageCollection
{
List<Image> images = new List<Image>();
public Image this[int i]
{
set
{
Image input = value;
// 他们可能在此处对input做了某些更改之后再放入内置的Image数组
// 透明的处理可能在此处完成
images[i] = input;
}
get
{
return images[i];
}
}
}
说白了,C#中的赋值可能会调用一段代码
至于那个Refresh,如果不加的话,代码执行完了不能立即看到效果
因为屏幕上看到的图像都是在缓冲器里的,更改了图像之后,必须触发重绘,才会生效,而调用refresh之前的几行代码都没有触发重绘。所以我们要主动调用refresh触发重绘
补充:.NET技术 , C#