简体   繁体   English

Delphi 2010 图像上的 Tbutton 褪色/闪烁

[英]Delphi 2010 image on Tbutton fading/blinking

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.当我设置按钮的 imageindex 和 images 属性(来自 imagelist 组件/pngs)时,启动程序并单击按钮,图像缓慢闪烁/淡入淡出。 How to prevent this and what seems to be the problem?如何防止这种情况以及似乎是什么问题?

Reviving an old topic...重温一个老话题……

After searching for a solution on internet and found nothing, I took a look in the TCustomButton code.在互联网上搜索解决方案后一无所获,我查看了 TCustomButton 代码。

It happens that, internaly, a button control on Windows has an imagelist with 6 images, as follows:碰巧,Windows 上的按钮控件内部有一个包含 6 个图像的图像列表,如下所示:

index 0: normal image索引 0:正常图像
index 1: hot image (when mouse is moving over button)索引 1:热图像(当鼠标移到按钮上时)
index 2: pressed image (while you hold the mouse button d own)索引 2:按下的图像(当您按住鼠标按钮时)
index 3: disabled image索引 3:禁用图像
index 4: selected image (when the button has focus, but is not pressed nor with mouse over it)索引 4:选定图像(当按钮具有焦点,但未按下或鼠标悬停时)
index 5: (the one that we need and can't be specified in TButton control; we'll talk about it) index 5:(我们需要的,不能在TButton控件中指定的,后面再说)

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".在Delphi中的TButton控件中,可以为“Images”属性设置一个ImageList,可以设置“ImageIndex”、“HotImageIndex”、“PressedImageIndex”、“DisabledImageIndex”和“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.设置此属性后,TButton 控件将创建另一个图像列表,并将您在属性中指定的索引从“图像”属性中的图像列表复制到新创建的图像列表中,按照我上面指定的顺序。

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

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.因此,当创建 window 时(在 OnCreate 事件上),我只需调用 MakeButtonImageStopBlinking 来为每个按钮提供图像作为参数,现在一切正常。

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.编辑:将 DoubleBufferd 设置为 True 将起作用,但它会从焦点按钮停止小 animation。 With the solution above, you can leave DoubleBuffered to False and you'll get it all (animation from aero and no fading out image).使用上面的解决方案,您可以将 DoubleBuffered 保留为 False,您将得到所有内容(来自 aero 的动画并且没有淡出图像)。

It appears to be a doubleBuffered property of a Tbutton.它似乎是 Tbutton 的 doubleBuffered 属性。 When set to false, the image blinks, when set to true it's working.当设置为 false 时,图像会闪烁,当设置为 true 时,它正在工作。 This occurs on Win 7 with aero enabled.这发生在启用了 aero 的 Win 7 上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM