Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove flickering from TSpeedButton

Tags:

delphi

Steps to reproduce:

  1. Add TPanel to a new VCL form and set Align = alClient.
  2. Add TSpeedButton to the panel and assign some bmp image to the Glyph property. (Optional but makes it clearer: Flat = True)
  3. Run the application, grab the bottom right corner of the form and move it around. The image in the TSpeedButton will flicker.

I read a lot about getting rid of flickering, but neither of the suggestions seem to work for a TSpeedButton:

  • There's no DoubleBuffered property
  • WS_EX_COMPOSITED can't be set, because it's not a TWinControl but a TGraphicControl
  • WM_ERASEBKGND message isn't received

In case it is of any importance, I'm actually using TPngSpeedButton, but since the actual problem lies within the TSpeedButton, I'm using that in the example.

Is there any solution for this?

Edit: For some reason nobody is able to reproduce this so far, so to make sure it's not my description, here's the dfm:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 337
  ClientWidth = 635
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 635
    Height = 337
    Align = alClient
    Caption = 'Panel1'
    TabOrder = 0
    object SpeedButton1: TSpeedButton
      Left = 64
      Top = 56
      Width = 32
      Height = 32
      Flat = True
      Glyph.Data = {
        360C0000424D360C000000000000360000002800000020000000200000000100
        180000000000000C000000000000000000000000000000000000FFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CED241C
        ED241CED241CED241CED241CED241CED241CED241CED241CED241CED241CED24
        1CED241CED241CED241CED241CED241CED241CED241CED241CEDFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CED241C
        ED241CED241CED241CED241CED241CED241CED241CED241CED241CED241CED24
        1CED241CED241CED241CED241CED241CED241CED241CED241CEDFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CED241C
        ED241CED241CED241CED241CED241CED241CED241CED241CED241CED241CED24
        1CED241CED241CED241CED241CED241CED241CED241CED241CEDFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CED241C
        ED241CED241CED241CED241CED241CED241CED241CED241CED241CED241CED24
        1CED241CED241CED241CED241CED241CED241CED241CED241CEDFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CED241C
        ED241CED241CED241CED241CED241CED241CED241CED241CED241CED241CED24
        1CED241CED241CED241CED241CED241CED241CED241CED241CEDFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDCC483FCC483F
        CC483FCC483FCC483FCC483FCC483F241CED241CED241CED241CED241CEDCC48
        3FCC483FCC483FCC483FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDCC483FCC483F
        CC483FCC483FCC483FCC483FCC483F241CED241CED241CED241CED241CEDCC48
        3FCC483FCC483FCC483FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDCC483FCC483F
        CC483FCC483FCC483FCC483FCC483F241CED241CED241CED241CED241CEDCC48
        3FCC483FCC483FCC483FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDCC483FCC483F
        CC483FCC483FCC483FCC483FCC483F241CED241CED241CED241CED241CEDCC48
        3FCC483FCC483FCC483FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CEDCC483FCC483F
        CC483FCC483FCC483FCC483FCC483F241CED241CED241CED241CED241CED241C
        ED241CED241CED241CED241CED241CED241CED241CED241CED241CED241CED24
        1CED241CED241CED241CED241CED241CED241CED241CED241CEDCC483FCC483F
        CC483FCC483FFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CED241C
        ED241CED241CED241CED241CED241CED241CED241CED241CED241CED241CED24
        1CED241CED241CED241CED241CED241CED241CED241CED241CEDCC483FCC483F
        CC483FCC483FFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CED241C
        ED241CED241CED241CED241CED241CED241CED241CED241CED241CED241CED24
        1CED241CED241CED241CED241CED241CED241CED241CED241CEDCC483FCC483F
        CC483FCC483FFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CED241C
        ED241CED241CED241CED241CED241CED241CED241CED241CED241CED241CED24
        1CED241CED241CED241CED241CED241CED241CED241CED241CEDCC483FCC483F
        CC483FCC483FFFFFFFFFFFFFFFFFFF241CED241CED241CED241CED241CED241C
        ED241CED241CED241CED241CED241CED241CED241CED241CED241CED241CED24
        1CED241CED241CED241CED241CED241CED241CED241CED241CEDCC483FCC483F
        CC483FCC483FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCC483FCC48
        3FCC483FCC483FCC483FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCC483FCC483F
        CC483FCC483FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCC483FCC48
        3FCC483FCC483FCC483FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCC483FCC483F
        CC483FCC483FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCC483FCC48
        3FCC483FCC483FCC483FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCC483FCC483F
        CC483FCC483FCC483FCC483FCC483FCC483FCC483FCC483FCC483FCC483FCC48
        3FCC483FCC483FCC483FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCC483FCC483F
        CC483FCC483FCC483FCC483FCC483FCC483FCC483FCC483FCC483FCC483FCC48
        3FCC483FCC483FCC483FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCC483FCC483F
        CC483FCC483FCC483FCC483FCC483FCC483FCC483FCC483FCC483FCC483FCC48
        3FCC483FCC483FCC483FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCC483FCC483F
        CC483FCC483FCC483FCC483FCC483FCC483FCC483FCC483FCC483FCC483FCC48
        3FCC483FCC483FCC483FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF}
    end
  end
end

And this is how it looks. In reality it's a little bit faster, but the captured video and gif conversion slows it down a bit.

like image 743
CodeX Avatar asked May 28 '18 13:05

CodeX


1 Answers

I was actually able to reproduce it on Windows 7 with Delphi 10.2.3 Tokyo. I have had similar problems quite often and since then I've been using this settings for all TPanel and its descendants, which worked in this case as well.

Panel1.DoubleBuffered := True;
Panel1.ParentBackground := False;
like image 93
Triber Avatar answered Nov 15 '22 06:11

Triber