To make transparent control, you must:
Make it opaque
ControlStyle := ControlStyle - [csOpaque]
Process WM_ERASEBKGND:
procedure TTransPanel.WM_ERASEBKGND(var Msg: TWM_ERASEBKGND); var SaveDCInd: Integer; Position: TPoint; begin SaveDCInd := SaveDC(Msg.DC); //save device context state (TCanvas does not have that func) GetViewportOrgEx(Msg.DC, Position); SetViewportOrgEx(Msg.DC, Position.X - Left, Position.Y - Top, nil); IntersectClipRect(Msg.DC, 0, 0, Parent.ClientWidth, Parent.ClientHeight); try Parent.Perform(WM_ERASEBKGND, Msg.DC, 0 ); Parent.Perform(WM_PAINT, Msg.DC, 0); //or // Parent.Perform(WM_PRINTCLIENT, Msg.DC, prf_Client); //Themeing except end; RestoreDC(Msg.DC, SaveDCInd); Canvas.Refresh; Msg.Result := 1; //We painted out background end;
In the above process, you first save the state of the device context, and then draw the canvas of our parent (possibly TForm) onto our canvas (TGroupBox). At the end, restore the DC and return 1 to indicate that we were painting the background.
source share