Unless someone has a better rationale, I would say: just do what respects simplicity and good practices such as "don't repeat yourself". 除非有人有更好的理论依据,否则我会说:做一些尊重简单性和良好做法的事情,例如“不要重复自己”。
Argument in favor or ImageList 支持赞成或ImageList的参数
- For small image collections that you set from the Visual Studio designer, it offers an ImageList editor that guide you and keeps related images together in the source code, rather than maintaining collections separately. 对于您从Visual Studio设计器中设置的小型图像集合,它提供了一个ImageList编辑器来指导您并将相关图像保留在源代码中,而不是单独维护集合。
- If some other Controls needs you to maintain an ImageList anyway, you've already paid the price, you may just as well use that for the Buttons, too. 如果其他控件仍然需要您维护ImageList,则您已经付出了代价,您也可以将其用于Buttons。
Argument in favor or Images 赞成观点或形象
When you have a choice: 当您有选择时:
The ImageList case ImageList案例
- ImageList needs you to somehow manages indexes to the images (integers or strings -- and string keying is buggy ? ), either explicitly or implicitly. ImageList需要您以某种方式显式或隐式管理图像的索引(整数或字符串- 字符串键是否有bug? )。
- The compiler cannot check if indexes or strings are misused anyway. 编译器仍然无法检查索引或字符串是否被滥用。
The Image case 图像盒
- You may not need to manage a collection. 您可能不需要管理集合。 You can use individual objects to set in the Image property. 您可以使用单个对象在Image属性中进行设置。
- Even the case when you need a collection is better. 即使需要收集的情况也更好。 You can index the collection using whatever key type you wish, for example a Dictionary. 您可以使用所需的任何键类型(例如字典)为集合建立索引。 If you index the collection with an Enum, the compiler can check at compile time and help you (Intellisense) at source code writing time. 如果使用Enum为集合建立索引,则编译器可以在编译时进行检查,并在源代码编写时为您提供帮助(Intellisense)。
Bottom line 底线
I'd favor the Image option and handle my own collection if needed using an Enum, but I would name that personal preference. 我希望使用“图像”选项,并在需要时使用枚举来处理我自己的收藏集,但我会说出个人喜好。