Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Clientbereich eines eigenen Controls beschränken (https://www.delphipraxis.net/152907-clientbereich-eines-eigenen-controls-beschraenken.html)

Bummi 12. Jul 2010 16:01

AW: Clientbereich eines eigenen Controls beschränken
 
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.

RSE 12. Jul 2010 16:31

AW: Clientbereich eines eigenen Controls beschränken
 
Hm, mit Align zu arbeiten wäre eine einfachere Möglichkeit gewesen, aber jetzt bin ich fast am Ziel :-) Ich habe folgendes programmiert:
Delphi-Quellcode:
    ...
    procedure SetHTMLCaptionHeight(const AValue: Integer); // löst alles aus

    procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
    procedure WMNCPaint(var Message: TWMNCPaint); message WM_NCPAINT;
    property HTMLCaptionHeight: Integer read FHTMLCaptionHeight write SetHTMLCaptionHeight;
    ...

procedure TCustomChoiceGroup.SetHTMLCaptionHeight(const AValue: Integer);
begin
  if FHTMLCaptionHeight = AValue then
    Exit;
  FHTMLCaptionHeight := AValue;
  // hier Win über notwendiges Resize informieren... wie?
end;

procedure TCustomChoiceGroup.WMNCCalcSize(var Message: TWMNCCalcSize);
begin // das muss nach SetHTMLCaptionHeight aufgerufen werden
  with Message.CalcSize_Params^ do
    Inc(rgrc[0].Top,FHTMLCaptionHeight); // Einschränkung des ClientRect
  inherited;
end;

procedure TCustomChoiceGroup.WMNCPaint(var Message: TWMNCPaint);
var
  DC: HDC;
  c: TCanvas;
begin // TCustomChoiceGroup.Canvas ist nur für den Client-Bereich
  c := TCanvas.Create;
  try
    DC := GetWindowDC(Handle);
    try
      c.Handle := DC;
      c.Brush.Color := Color;
      c.FillRect(Rect(0,0,Width,FHTMLCaptionHeight));
      HTMLDraw(c,Rect(0,0,Width,FHTMLCaptionHeight),HTMLCaption,False);
    finally
      ReleaseDC(Handle, DC);
    end;
  finally
    c.free;
  end;
  Message.Result := 0;
end;
Mit InvalidateRect kann ich Neuzeichnen initiieren, aber was muss ich für eine Message verschicken, damit ich WM_NCCALCSIZE zurückbekomme? Die ganzen VCL-Lösungen beziehen sich offenbar auf die Client-Area.

Edit:
Da sich die restliche Frage mehr auf die WinAPI bezieht, werde ich den Rest mal im entsprechenden Forum zu Ende führen:
http://www.delphipraxis.net/152921-w...geaendert.html


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:10 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz