Chris,

Aligning on a scroll box does not make much sense.  Imagine if you have one
control aligned to alClient.  This is telling the VCL code to align the
control to the entire client region of the scrollbox.  On the other hand,
the client area of the scroll box is dynamically adjusted to fit in all
child controls!  I.e., you have a design concept problem.

The solution is to place the TPanel on the scroll box, size the panel to fit
your requirements.  Now, all controls will align on the TPanel, while you
can use the scrollbox to scoll hidden controls into view.  The only thing
that does not work in this scheme is the ScrollToView method.  You will need
to override that and hack it so that it knows about child controls on the
panel.

Hope this helps.
Dennis.

> 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
>

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to