I have a need to create a new TScrollBox control that will allow my to align
child controls using a user defined border width. I need to have a space
around any aligned control of 5 pixels on the left, right, top & bottom
edges of the scroll box.
Below is the code I have, and then below that is the same code for a custom
Tpanel. The code for the TPanel works fine, but the scrollbox just ignores
the code I have included and uses a border of nothing when aligning the
child controls.
unit AdrockScrollBox;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TAdrockScrollBox = class(TScrollBox)
private
FBorderWidth: Integer;
procedure SetBorderWidth(const Value: Integer);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
Constructor Create(Aowner : TComponent); override;
Procedure AlignControls(AControl: TControl; var Rect: TRect);
override;
published
{ Published declarations }
property BorderWidth : Integer read FBorderWidth write SetBorderWidth
default 5;
end;
procedure Register;
implementation
Procedure TAdrockScrollBox.AlignControls(AControl: TControl; var Rect:
TRect);
begin
InflateRect(Rect, -BorderWidth, -BorderWidth);
inherited AlignControls(AControl, Rect);
end;
constructor TAdrockScrollBox.Create(Aowner: TComponent);
begin
Inherited Create(Aowner);
FBorderWidth := 5
end;
procedure TAdrockScrollBox.SetBorderWidth(const Value: Integer);
begin
FBorderWidth := Value;
Realign;
Invalidate;
end;
procedure Register;
begin
RegisterComponents('Adrock', [TAdrockScrollBox]);
end;
end.
=======================================================
unit AdrockPanelX;
interface
uses
Windows, Messages, SysUtils, Extctrls,Classes, Graphics, Controls, Forms,
Dialogs;
type
TAdrockPanelXYZ = class(Tpanel)
private
FBorderWidth: Integer;
procedure SetBorderWidth(const Value: Integer);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
Constructor Create(Aowner : TComponent); override;
Procedure AlignControls(AControl: TControl; var Rect: TRect);
override;
published
{ Published declarations }
property MyBorderWidth : Integer read FBorderWidth write SetBorderWidth
default 5;
end;
procedure Register;
implementation
Procedure TAdrockPanelXYZ.AlignControls(AControl: TControl; var Rect:
TRect);
begin
InflateRect(Rect, -MyBorderWidth, -MyBorderWidth);
inherited AlignControls(AControl, Rect);
end;
constructor TAdrockPanelXYZ.Create(Aowner: TComponent);
begin
Inherited Create(Aowner);
FBorderWidth := 5
end;
procedure TAdrockPanelXYZ.SetBorderWidth(const Value: Integer);
begin
FBorderWidth := Value;
Realign;
Invalidate;
end;
procedure Register;
begin
RegisterComponents('Adrock', [TAdrockPanelXYZ]);
end;
end.
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz