How to make Delphi TFrame background transparent

I actually think this method will work for Visual Basic and other similar languages too. Here is the code for a sample frame called TfrKnob:


unit Knob;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, VrControls, VrWheel;

type
  TfrKnob = class(TFrame)
    vwKnob: TVrWheel;
    lPos: TLabel;
    procedure CreateParams(var Params: TCreateParams);override;
    procedure PaintWindow(DC: HDC); override;
  private
    { Private declarations }
  public
    constructor Create(AOwner:TComponent);override;
    { Public declarations }
  end;

implementation

{$R *.dfm}

constructor TfrKnob.Create(AOwner: TComponent);
begin
  inherited;
  Brush.Style := bsClear;
end;

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

procedure TfrKnob.PaintWindow(DC: HDC);
begin
// keep this comment or Delphi will loose this method implementation
end;

end.


New code is in bold font.

This is very sad, but just a few years ago there were way more information about Delphi in the Internet and now this excellent development environment and language seem dying. It’s good to know it is still in top 10, though.

3 thoughts on “How to make Delphi TFrame background transparent

Leave a Reply