图片列表使用
我将应用程序的图标存储在多个图像列表中。
有一个:
X16
X24
X48
X32
TAction 和直接访问将 ICO 放入 TButton 或 TImage 都来自这几个图像列表。
我的问题是,当我需要删除一个噩梦时
,我想到为每个人设置一个 CONST 值,但由于有些值在 TActions 中使用,这不是一个完整的解决方案。
你们是如何做到这一点的?你们有什么解决方案来解决或至少改进这个问题? 我使用DELPHI 2007。
I store the icons for my applications inside several image lists.
Have one to:
X16
X24
X48
X32
Both TActions and direct access to place ICOs in a TButton, or TImage came from this several Image Lists.
My problem is that when I need to remove one its nightmare
I thought of setting a CONST value to everyone, but as some are used in TActions it’s not a complete solution.
How are you guys doing this and what solutions do you have to solve or at least improve this?
I use DELPHI 2007.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我所做的是在运行时通过从资源加载来添加所有图标。添加它们时,我将添加的图标的索引保存到全局变量中。我还通过引用这些全局变量在运行时分配每个操作的 ImageIndex 属性。
这样可以灵活地向项目添加和删除图标,而不会出现编号问题。该方法适合基于字体缩放的运行时图标大小决策。缺点是您在设计时看不到图像,这是一个缺点。如果您想拥有上述所有灵活性,我没有看到更好的解决方案。在理想情况下,图像将通过名称或 ID 来标识,而不是通过数组中的连续索引来标识。但要实现这一点,您需要在 VCL 之上实现大量代码。
What I do is add all the icons at runtime by loading from then from resources. When I add them I save the index of the added icon to a global variable. I also assign the ImageIndex property of each action at runtime by referring to these global variables.
This allows flexibility to add and remove icons to the project without having numbering problems. The approach caters for runtime icon size decisions based on font scaling. The drawback is that you don't get to see the images at design time which is a drawback. If you want to have all the flexibility outlined above I don't see a better solution. In an ideal world the images would be identified by a name or an ID rather than a contiguous index into an array. But to achieve that you would need to implement a lot of code on top of the VCL.
这个问题有多种解决方案。
如果您想使用常量,但不想在每次删除图像时都更改它们。您可以执行以下操作:
当您想要删除图像 D 时,只需更改两行即可:
另一种方法是使用枚举类型:
您可以使用 Ord 运算符来获取图像索引:
There are several solutions to this problem.
If you want to use constants, but you don´t want to change them all each time you remove an image. You can do the following:
When you want to remove image D, you only need to change two lines:
Another way is to work with enum types:
You can use the Ord operator to get the image index: