问题
Is anyone aware of an existing Delphi component, that is
- properly themed like a TButton (has a fade in/fade out effect upon mouse hover in Windows 7 and above)
- supports Glyphs like TBitBtn but WITHOUT using ImageLists (the same way TBitBtn does).
If there is no such component available, would it be possible to modify TBitBtn's themed behaviour to replicate that of a TButton? I'm not a master of theming, but maybe you could get the different fade-in fade-out phases from ThemeServices? Or would you have to create the fade effect yourself from avaraging between the hot and non-hot state?
回答1:
The reason that the VCL TButton
implements image support using image lists is that is how the underlying Win32 BUTTON
control supports images. If you want to have the full theme support with fade-in/fade-out animations then you need to use the native control. Well, you could try to replicate these effects yourself, but I think that the chance of success are low, and you'd always be subject to future changes in themeing. Which is what is biting you with TBitBtn
.
So, the way to solve your problem is to use a TButton
control with an image list. The implementation of TButton
uses a private image list in any case because the indices needed by the underlying control are fixed. So the TButton
control takes a copy of your images anyway. So you could easily write your own button control, based on TButton
or one of its ancestors, that exposes a glyph property. And then pushed that glyph into an image list, and then in to the underlying Win32 control.
If you have a Delphi version that does not support ImageList
and ImageIndex
properties, you'll need to implement your own button control that wraps the Win32 BUTTON
control.
来源:https://stackoverflow.com/questions/25929844/is-there-a-component-that-behaves-like-a-tbitbtn-that-is-properly-themed