Image of Delphi 2010 on Tbutton Fade / Blink

When I set the imageindex property and the Button images (from imagelist component / pngs), run the program and click the button, the image slowly or slowly flashes / fades. How to prevent this and what seems like a problem?

+4
source share
2 answers

This seems to be a doubleBuffered property for Tbutton. If set to false, the image blinks when set to true. This happens on Win 7 with aero enabled.

+3
source

The revival of the old theme ...

After searching for a solution on the Internet and found nothing, I looked at the TCustomButton code.

It happens that inside, the button control in Windows has an image with 6 images, as shown below:

index 0: normal image
index 1: hot image (when the mouse button moves)

index 2: pressed image (while you hold the mouse button d yourself)
index 3: disabled image
index 4: selected image (when the button has focus but is not pressed and does not hover over it)
index 5: (the one we need and cannot be specified in the TButton control, we'll talk about it)

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

Using this set of properties, the TButton control creates an ANOTHER image list and copies the indexes you specify in the properties from the image list in the Images property to this new list of created images in the above order.

The problem is that when you focus the control, Win 7 Aero has such an effect that it fades out and highlights the highlight color (small animation), and it used the 6th image from the internal image list to also fade in and out, but IMPOSSIBLE supply this FADE image index to control TButton, so I created a simple solution that works for me, but I have to call RunTime. (you can get a new class from TCustomButton and create a new control that you can set, for example, in SelectedFadeImageIndex, but I did not).

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 (in the OnCreate event), I just call MakeButtonImageStopBlinking, attaching each button with the image as a parameter, and now it all works.

Sry in order to resume such an old topic, but it seems that there was no answer to this question (or I could not search correctly).

Edit: Setting DoubleBufferd to True will work, but it will stop the small animation from the focus button. Using the above solution, you can leave DoubleBuffered to False and you get everything (animation from aero and no image attenuation).

+8
source

All Articles