2

I created a control based on TGraphicControl that is transparent and mostly empty space. It actually implements a simple symbol in line art. i.e. TLFMagicControl = class(TGraphicControl)

In the constructor which I have:

ControlStyle := ControlStyle + [csOpaque];

My "TLFMagicControl" is then placed on my own panel that is a TCustomControl. i.e. TLFGridPanel = class(TCustomControl)

The transparency of the TLFMagicControl works perfectly interacting with each other but not with the parent panel they are on (TLFGridPanel).

The TLFGridPanel spends most of its time just black so its not an issue but I want to user to be able to turn on/off grid lines on the panel. When I override the paint handler TLFGridPanel and draw my grid the controls placed on top are not transparent and block the grid lines underneath.

Is there a way around this for a TCustomControl or have I chosen the wrong base for my panel?

Example of non transparent controls

tarzanbappa
  • 4,930
  • 22
  • 75
  • 117
Martin
  • 815
  • 8
  • 21

1 Answers1

1

csOpaque tells the VCL that you draw the control entirely by yourself, which supresses the automatic background drawing (or erasing). Remove that control style in order to let WM_ERASEBKGND do its work.

NGLN
  • 43,011
  • 8
  • 105
  • 200
  • I totally misunderstood how that controlstyle directive worked - thanks. While this does work its not 100% in that as I click and drag the GraphicControl around it leaves "holes" where the backgorund grid is not being redrawn - any thoughts? – Martin Sep 21 '15 at 09:00
  • Call `Parent.Update` as soon as your drag operation starts, but that might result in minor flickering. For other drawing and anti-flicker techniques, see [Best way to do non-flickering, segmented graphics updates in Delphi](http://stackoverflow.com/q/6363954/757830). – NGLN Sep 21 '15 at 20:15
  • 1
    Also try looking at the VCL source code for `TLabel`, which is a transparent-capable `TGraphicControl`-derived control. – Remy Lebeau Sep 22 '15 at 19:28