expanel.pas

来自「Delphi, typed list generator code snippl」· PAS 代码 · 共 103 行

PAS
103
字号
unit Expanel;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, ExtCtrls;

type
  TExPanel = class(TPanel)
  private
    { Private-Deklarationen }
    FSpacingLeft: Integer;
    FSpacingTop: Integer;
    FSpacingRight: Integer;
    FSpacingBottom: Integer;

    Procedure SetSpacingLeft( value: Integer );
    Procedure SetSpacingTop( value: Integer );
    Procedure SetSpacingRight( value: Integer );
    Procedure SetSpacingBottom( value: Integer );
  protected
    { Protected-Deklarationen }
    procedure AlignControls(AControl: TControl; var Rect: TRect); override;
  public
    { Public-Deklarationen }
    constructor Create(AOwner: TComponent); override;
  published
    { Published-Deklarationen }
    property SpacingLeft:Integer read FSpacingLeft write SetSpacingLeft default 8;
    property SpacingTop:Integer read FSpacingTop write SetSpacingTop default 8;
    property SpacingRight:Integer read FSpacingRight write SetSpacingRight default 8;
    property SpacingBottom:Integer read FSpacingBottom write SetSpacingBottom default 8;
  end;

procedure Register;

implementation

constructor TExPanel.Create(AOwner: TComponent);
  Begin
    inherited Create( aOwner );
    FSpacingLeft := 8;
    FSpacingTop := 8;
    FSpacingRight := 8;
    FSpacingBottom := 8;
    ControlStyle := ControlStyle - [csSetCaption];
  End;

Procedure TExPanel.SetSpacingLeft( value: Integer );
  Begin
    If FSpacingLeft <> value Then Begin
      FSpacingLeft := value;
      Realign;
      Invalidate;
    End;
  End;

Procedure TExPanel.SetSpacingTop( value: Integer );
  Begin
    If FSpacingTop <> value Then Begin
      FSpacingTop := value;
      Realign;
      Invalidate;
    End;
  End;

Procedure TExPanel.SetSpacingRight( value: Integer );
  Begin
    If FSpacingRight <> value Then Begin
      FSpacingRight := value;
      Realign;
      Invalidate;
    End;
  End;

Procedure TExPanel.SetSpacingBottom( value: Integer );
  Begin
    If FSpacingBottom <> value Then Begin
      FSpacingBottom := value;
      Realign;
      Invalidate;
    End;
  End;

procedure TExPanel.AlignControls(AControl: TControl; var Rect: TRect);
 Begin
   With Rect Do Begin
     Left := Left + FSpacingLeft;
     Top  := Top + FSpacingTop;
     Right := Right - FSpacingRight;
     Bottom := Bottom - FSpacingBottom;
   End;
   inherited AlignControls( AControl, Rect );
 End;

procedure Register;
begin
  RegisterComponents('PBGoodies', [TExPanel]);
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?