Einzelnen Beitrag anzeigen

Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#11

AW: Clientbereich eines eigenen Controls beschränken

  Alt 12. Jul 2010, 17:01
vielleicht kannst Du aus diesem Versuch was basteln??

Delphi-Quellcode:
unit Unit5;

interface

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

type
  TMyWrapper=Class(TWincontrol)

  End;
  TMyComponent=Class(TwinControl)
    private
    MyParent:TWinControl;
    FLabel:TLabel;
    Constructor Create(AOwner:TComponent);override;
    Destructor Destroy;override;
    function GetParent: TwinControl;
    procedure SetParent(const Value: TwinControl);
    function Getheight: Integer;
    function GetWidth: Integer;
    procedure SetHeight(const Value: Integer);
    procedure SetWidth(const Value: Integer);
    public
    published
    Property Parent:TwinControl Read GetParent Write SetParent;
    Property Width:Integer read GetWidth Write SetWidth;
    Property Height:Integer read Getheight Write SetHeight;
  End;

  TForm5 = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    Panel1: TPanel;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form5: TForm5;

implementation

{$R *.dfm}

{ TMyComponent }

constructor TMyComponent.Create(AOwner: TComponent);
begin
   inherited create(AOwner);
   MyParent:=TMyWrapper.Create(nil);
   FLabel:=TLabel.Create(nil);
   Flabel.parent := MyParent;
   Flabel.Align := alTop;
   Flabel.Caption :='Test';
   inherited Parent := MyParent;
   Align := alClient;
end;

destructor TMyComponent.Destroy;
begin
  Parent := nil;
  Flabel.Free;
  inherited;
end;

function TMyComponent.Getheight: Integer;
begin
    Result := MyParent.Height;
end;

function TMyComponent.GetParent: TwinControl;
begin
  Result := MyParent.Parent;
end;

function TMyComponent.GetWidth: Integer;
begin
    Result := MyParent.Width;
end;

procedure TMyComponent.SetHeight(const Value: Integer);
begin
       MyParent.Height:= value;
end;

procedure TMyComponent.SetParent(const Value: TwinControl);
begin
   MyParent.Parent := value;
end;

procedure TMyComponent.SetWidth(const Value: Integer);
begin
         MyParent.Width:= value;
end;

procedure TForm5.Button1Click(Sender: TObject);
var
  my:TMyComponent;
  b:TButton;
begin
  my:=TMyComponent.Create(Self);
  With my do
    begin
      parent := panel1;
      width := 100;
      Height := 100;
    end;
  b := TButton.Create(my);
  With b do
    begin
      top := 0;
      left := 0;
      Width := 100;
      Height := 20;
      Caption :='Test';
      parent := my;
    end;
end;

end.
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat