Delphi 5 transparency breaks child draw

83 Views Asked by At

I have a control in Delphi 5 like this (following this post: https://tips.delphidabbler.com/tips/74.html):

type
  TTransparentGroupbox = class(TGroupBox)
  protected
    procedure CreateParams(var params: TCreateParams); override;
    procedure WMEraseBkGnd(var msg: TWMEraseBkGnd); message WM_ERASEBKGND;
  end;

.....

procedure TTransparentGroupbox.CreateParams(var params: TCreateParams);
begin
  inherited CreateParams(params);
  params.ExStyle := params.ExStyle or WS_EX_TRANSPARENT;
end;

procedure TTransparentGroupbox.WMEraseBkGnd(var msg: TWMEraseBkGnd);
begin
  SetBkMode(msg.DC, TRANSPARENT);
  msg.result := 1;
end;

But I have trouble when it is redrawn. The portion not blurred should be listbox on such a TTransparentGroupbox, but it is not entirely redrawn, as if the background mode would have been propagated to the children but they are repainted on the TWinControl level. I have tried to set it back to OPAQUE at the only point I could override, but with no success:

procedure TTransparentGroupbox.PaintWindow(DC: HDC);
begin
   SetBkMode(DC, OPAQUE);
   inherited;
end;

enter image description here

enter image description here

The annoying part is, that I have other TTransparentGroupbox instances, with other TListBox instances that do not behave in this way.

The second problem I have is that whenever the visibility of a child control is changed to false, it is not "erased".

0

There are 0 best solutions below