T 按钮上的 Delphi 2010 图像褪色/闪烁

发布于 2024-11-18 00:12:46 字数 93 浏览 3 评论 0原文

当我设置按钮的 imageindex 和 images 属性(来自图像列表组件/png)时,启动程序并单击按钮,图像缓慢闪烁/淡入淡出。如何防止这种情况发生?问题出在哪里?

When I set the imageindex and images property of a Button (from a imagelist component/pngs), start the program and click the button, the image is blinking slowly/ fading in and out. How to prevent this and what seems to be the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暮年 2024-11-25 00:12:46

重温一个老话题……

在网上搜索解决方案后一无所获,我查看了TCustomButton代码。

碰巧,Windows 上的按钮控件内部有一个包含 6 个图像的图像列表,如下所示:

索引 0:普通图像
索引 1:热点图像(当鼠标移到按钮上时)
索引 2:按下的图像(当您按住鼠标按钮时)
索引 3:禁用图像
索引 4:选定的图像(当按钮具有焦点,但未按下或鼠标悬停在其上时)
索引 5:(我们需要但不能在 TButton 控件中指定的索引;我们将讨论它)

在Delphi的TButton控件中,可以为“Images”属性设置一个ImageList,并且可以设置“ImageIndex”、“HotImageIndex”、“PressedImageIndex”、“DisabledImageIndex”和“SelectedImageIndex”。

设置此属性后,TButton 控件将创建另一个图像列表,并将您在属性中指定的索引从“图像”属性中的图像列表复制到新创建的图像列表,按照我上面指定的顺序。

问题是,当您聚焦控件时,Win 7 Aero 具有淡入和淡出突出显示颜色(一个小动画)的效果,并且它还使用内部图像列表中的第 6 个图像淡入和淡出,但不可能向 TButton 控件提供“FADE”图像索引,因此我创建了一个适合自己的简单解决方案,但我必须在运行时调用。 (您可以从 TCustomButton 派生一个新类并创建一个新控件,例如您可以设置新的 SelectedFadeImageIndex,但我没有)。

我创建了这个程序:

    procedure MakeButtonImageStopBlinking(AButton: TCustomButton);
    var
      ButtonImageList: TButtonImageList;
      Icon: HICON;
    begin
      SendMessage(AButton.Handle, BCM_GETIMAGELIST, 0, LPARAM(@ButtonImageList));
      Icon := ImageList_GetIcon(ButtonImageList.himl, 0, ILD_NORMAL);
      ImageList_AddIcon(ButtonImageLIst.himl, Icon);
      DestroyIcon(Icon);
    end;

因此,当创建窗口时(在 OnCreate 事件上),我只需调用 MakeButtonImageStopBlinking 来提供每个以图像为参数的按钮,现在一切都可以工作了。

很抱歉重提这样一个古老的话题,但似乎没有任何答案(或者我无法正确搜索)。

编辑:将 DoubleBufferd 设置为 True 会起作用,但它会停止焦点按钮上的小动画。使用上面的解决方案,您可以将 DoubleBuffered 保留为 False,然后您将获得所有内容(来自 aero 的动画并且没有淡出图像)。

Reviving an old topic...

After searching for a solution on internet and found nothing, I took a look in the TCustomButton code.

It happens that, internaly, a button control on Windows has an imagelist with 6 images, as follows:

index 0: normal image
index 1: hot image (when mouse is moving over button)
index 2: pressed image (while you hold the mouse button d own)
index 3: disabled image
index 4: selected image (when the button has focus, but is not pressed nor with mouse over it)
index 5: (the one that we need and can't be specified in TButton control; we'll talk about it)

In the TButton control in Delphi, you can set an ImageList to the "Images" property, and you can set "ImageIndex", "HotImageIndex", "PressedImageIndex", "DisabledImageIndex" and "SelectedImageIndex".

With this properties set, the TButton control creates ANOTHER image list, and copy the indexes you specified in the properties from the image list in the "Images" property to that new created image list, in the order I specified above.

The problem is, when you focus the control, Win 7 Aero has that effect that it fades in and out the highlight color (a little animation), and it used the 6th image from it's internal image list to fade in and out to also, but it is IMPOSSIBLE to supply that "FADE" image index to TButton control, so I have created a simple solution that is working for myself, but I have to call in RunTime. (you could derive a new class from TCustomButton and create a new control that you can set a new SelectedFadeImageIndex for example, but I didnt).

I created this procedure:

    procedure MakeButtonImageStopBlinking(AButton: TCustomButton);
    var
      ButtonImageList: TButtonImageList;
      Icon: HICON;
    begin
      SendMessage(AButton.Handle, BCM_GETIMAGELIST, 0, LPARAM(@ButtonImageList));
      Icon := ImageList_GetIcon(ButtonImageList.himl, 0, ILD_NORMAL);
      ImageList_AddIcon(ButtonImageLIst.himl, Icon);
      DestroyIcon(Icon);
    end;

so, when the window is created (on OnCreate event), i just call MakeButtonImageStopBlinking suppling each button that has image as it's parameter, and it all now works.

Sry for revving such an old topic, but it seems to be no answer for that anyware (or I wasn't able to search properly).

Edit: Setting DoubleBufferd to True will work, but it will stop the little animation from the button with focus. With the solution above, you can leave DoubleBuffered to False and you'll get it all (animation from aero and no fading out image).

千柳 2024-11-25 00:12:46

它似乎是 Tbutton 的 doubleBuffered 属性。当设置为 false 时,图像会闪烁,当设置为 true 时,图像会正常工作。在启用了 aero 的 Win 7 上会发生这种情况。

It appears to be a doubleBuffered property of a Tbutton. When set to false, the image blinks, when set to true it's working. This occurs on Win 7 with aero enabled.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文