Hi,

What am I doing wrong, or is this another LCL bug? FMyContainer, FLabel and
FButton are private field variables of TForm1. I create the three
components at runtime.

FMyContainer is a TCustomControl descendant that has [csOpaque] excluded
from ControlStyle because I want the container component to be transparent.
Yet at runtime, the component is NOT transparent.

I am painting a tiled image directly on the Canvas of TForm1, so I should
be able to see the background image thru my custom container, but I can't.

Screenshot-1.png = The form with a tiled background image.
Screenshot-2.png = The same form as above, but with my three runtime
    created components added. My custom container seems to be ignoring the
    csOpaque style.


Below is the complete code for Unit1.pas


-------------------------------------------------------------
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics,
  Dialogs, ExtCtrls, StdCtrls;

type
  TMyContainer = class(TCustomControl)
  public
    constructor Create(AOwner: TComponent); override;
  end;

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
  private
    FMyContainer: TMyContainer;
    FLabel: TLabel;
    FButton: TButton;
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation


{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  FMyContainer := TMyContainer.Create(self);
  FMyContainer.Parent := self;
  FMyContainer.Align := alClient;

  FLabel := TLabel.Create(FMyContainer);
  with FLabel do
  begin
    Parent := FMyContainer;
    Top := 10;
    left := 20;
    AutoSize := True;
    Caption := 'we are in a custom transparent container';
  end;

  FButton := TButton.Create(FMyContainer);
  with FButton do
  begin
    Parent := FMyContainer;
    Top := 10;
    Left := 200;
    Caption := 'Click me';
  end;
end;

procedure TForm1.FormPaint(Sender: TObject);
var
  x, y: Integer;
  MyBmp: TPixmap;
begin
  MyBmp := TPixmap.Create;
  try
    MyBmp.LoadFromFile('./login-bckgnd.xpm');
    for x := 0 to (Width div MyBmp.Width) do
      for y := 0 to (Height div MyBmp.Height) do
        Canvas.Draw(x * MyBmp.Width, y * MyBmp.Height, MyBmp);
  finally
    MyBmp.Free;
  end;
end;

{ TMyContainer }

constructor TMyContainer.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  // Do not include [csOpaque] because we want a transparent widget.
  ControlStyle := [csAcceptsControls, csNoFocus];
end;

initialization
  {$I Unit1.lrs}

end.

-------------------------------------------------------------


Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/

<<inline: Screenshot-1.png>>

<<inline: Screenshot-2.png>>

--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to