Delphi 2010 image on Tbutton fading/blinking

守給你的承諾、 提交于 2019-12-06 04:46:06

问题


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?


回答1:


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).




回答2:


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.



来源:https://stackoverflow.com/questions/6551323/delphi-2010-image-on-tbutton-fading-blinking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!