[英]Unable to modify items in the collection Keys of Forms.ImageList.Images
I'm using my first dotnet TreeView
and I have a problem with ImageList
Keys. 我正在使用我的第一个dotnet TreeView
并且ImageList
键有问题。
When I write this code : 当我写这段代码时:
int i;
i = MyIL.Images.Add(Properties.Resources.CheckedItemBitmap, Color.White);
MyIL.Images.Keys[i] = "Checked";
The key
is not written. key
未写入。 I mean that MyIL.Images.Keys[i]
is still empty after that code. 我的意思是该代码之后MyIL.Images.Keys[i]
仍然为空。 It looks like that it is read only. 看起来它是只读的。 But the documentation says that one can set values in it. 但是文档说可以在其中设置值。
This is a problem because I want to use this specific overloaded ImageList.Images.Add()
function, that doesn't let me specify the key value. 这是一个问题,因为我想使用此特定的重载ImageList.Images.Add()
函数,该函数不允许我指定键值。
This is not the end of the world, but any clue would be appreciated. 这不是世界末日,但任何线索都将不胜感激。
As you observed, according to the documentation , the Keys
property is read-only. 如您所见,根据文档 , Keys
属性是只读的。 The key is normally something that is set when you add the item to the collection, and sure enough, there is an overload of Images.Add
that accepts a custom key. 密钥通常是在将项目添加到集合时设置的,并且可以肯定的是, Images.Add
的重载可以接受自定义密钥。 So I would use that overload, and set the transparent colour in a separate call: 因此,我将使用该重载,并在单独的调用中设置透明颜色:
Properties.Resources.CheckedItemBitmap.MakeTransparent(Color.White);
MyIL.Images.Add("Checked", Properties.Resources.CheckedItemBitmap);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.