让禁用的菜单和工具栏图像看起来更好?
请参阅随附的屏幕截图,其中说明了我的一个程序中的 TToolBar:
注意最后两张图像工具栏,它们被禁用。它们被绘制为禁用的方式并不是很吸引人,事实上在 Delphi IDE 中,一些图像看起来是一样的。
我遇到的问题是我希望我的应用程序看起来更干净。禁用项目的绘制方式看起来不太好。 TToolBar 允许设置禁用的 TImageList,我尝试将图像设为黑色和白色。白色,但它们看起来不正确,并且宁愿不必总是将图像设为黑白(时间和精力)。这个问题也出现在我的菜单和弹出菜单中,无论如何它们都不允许禁用图像。
有没有办法对禁用的项目进行涂漆,使其看起来更好看?
如果可能的话,我宁愿不使用第三方控件。我知道 Jedi 组件允许禁用菜单等图像,但更喜欢一种不诉诸第三方组件的方法,如果可能的话,我更喜欢使用标准问题 VCL,特别是有时我使用 TActionMainMenuBar 来绘制 Office 风格菜单,当 DrawingStyle 设置为渐变时,它与 TToolBar 匹配。
编辑
我已经接受了 RRUZ 的答案,是否也可以接受 David 的答案,两者都是非常好的答案,如果可能的话,希望在他们之间共享答案。
谢谢。
Please see the attached screenshot which illustrates a TToolBar from one of my programs:
Notice the last two images of the Toolbar, they are disabled. The way they have been drawn to appear disabled is not very appealing, in fact in the Delphi IDE some of the images look the same.
The issue I have with it is I want my application to look a lot cleaner. The way the disabled items are drawn doesn't look very good. The TToolBar allows to set a disabled TImageList, I tried making my images black & white but they didn't look right, and would rather not have to always make the images black and white (time and effort). This problem also shows in my menus and popup menus, which don't allow for disabled images anyway.
Is there a way to paint the disabled items to look better on the eye?
If possible I would rather not look to use 3rd Party Controls. I know the Jedi Components allow disabled images for the menu etc, but would prefer a way to not resort too 3rd Party Components, when possible I would much prefer to use the standard issue VCL, especially as sometimes I use the TActionMainMenuBar to draw Office Style menus, which match the TToolBar when DrawingStyle is set to gradient.
EDIT
I have accepted RRUZ's answer, is it possible though to accept David's answer as well, both are very good answers and would like the answer to be shared between them if possible.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
前段时间我写了一个补丁来解决这个问题。关键是修补
TCustomImageList.DoDraw
< 的代码/a> 函数,所使用的技术类似于delphi-nice-toolbar
应用程序,但在本例中我们不是修补 bpl IDE,而是修补内存中的函数。只需将此单元包含在您的项目中
,结果将是
Sometime Ago i wrote a patch to fix this behavior. the key is patch the code of the
TCustomImageList.DoDraw
function, the technique used is similar to the used by thedelphi-nice-toolbar
app, but instead of patch a bpl IDE in this case we patch the function in memory.Just include this unit in your project
and the result will be
我一年多前针对相关问题提交了质量控制报告,但是那是菜单用的。我从未在
TToolbar
中看到过这种情况,因为它是公共控件的包装器,并且绘图是由 Windows 处理的。然而,您看到的图像显然是 VCL 调用 TImageList.Draw 并传递 Enabled=False 的结果 - 没有其他看起来那么糟糕!您 100% 确定这确实是
TToolbar
吗?修复方法肯定是避免
TImageList.Draw
并使用ILS_SATURATE
调用ImageList_DrawIndirect
。您可能需要修改一些VCL源代码。首先找到自定义绘制工具栏的位置,然后调用此例程而不是调用
TImageList.Draw
。更好的解决方法是找出为什么要自定义绘制工具栏,并找到一种方法让系统执行此操作。
编辑1
我查看了Delphi源代码,我猜测您正在自定义绘制工具栏,也许是因为它有渐变。我从来不知道 TToolbar 可以处理自定义绘图,但我只是一个普通的人!
无论如何,我可以在
TToolBar.GradientDrawButton
中看到调用TImageList.Draw
的代码,所以我认为上面的解释是正确的。我相当确定调用上面的
DrawDisabledImage
函数会给您带来更好的结果。如果在调用TImageList.Draw
时能够找到一种方法来实现这一点,那么我认为这将是最好的解决方案,因为它将适用于批发。编辑2
将上面的函数与@RRUZ的答案结合起来,你就有了一个很好的解决方案。
I submitted a QC report for a related issue over a year ago, but that was for menus. I've never seen this for
TToolbar
since it is a wrapper to the common control and the drawing is handled by Windows.However, the images you are seeing are clearly as result of the VCL calling
TImageList.Draw
and passingEnabled=False
– nothing else looks that bad! Are you 100% sure this really is aTToolbar
?The fix will surely be to avoid
TImageList.Draw
and callImageList_DrawIndirect
with theILS_SATURATE
.You may need to modify some VCL source. First find the location where the toolbar is being custom drawn and call this routine instead of the calls to
TImageList.Draw
.An even better fix would be to work out why the toolbar is being custom drawn and find a way to let the system do it.
EDIT 1
I've looked at the Delphi source code and I'd guess that you are custom drawing the toolbar, perhaps because it has a gradient. I never even knew that TToolbar could handle custom drawing but I'm just a plain vanilla kind of guy!
Anyway, I can see code in
TToolBar.GradientDrawButton
calling theTImageList.Draw
so I think the explanation above is on the right track.I'm fairly sure that calling my
DrawDisabledImage
function above will give you better results. If could find a way to make that happen when you callTImageList.Draw
then that would, I suppose, be the very best fix since it would apply wholesale.EDIT 2
Combine the function above with @RRUZ's answer and you have an excellent solution.
如果您在 ActionToolBar 中使用 LargeImages,@RRUZ 的解决方案将不起作用。我对 @RRUZ 代码进行了更改,以便在 ActionToolBar 中使用 LargeImages。
Solution from @RRUZ dosn't work if you use LargeImages in ActionToolBar. I made changes to the @RRUZ code to work with LargeImages in ActionToolBar.
查看此 Delphi IDE 修复。也许你可以模仿它的实现。
Take a look at this Delphi IDE fix. Maybe you can mimic it's implementation.
使用 TActionToolbar , TActionmanager , Timagelist
将操作管理器图像列表设置为 Timagelist。并将Disabledimages设置为另一个图像列表
Use TActionToolbar , TActionmanager , Timagelist
Set action managers image list to a Timagelist. and set Disabledimages to another imagelist