Title: Automatically enable constrains while still able to resize form
Question: A way to ensure your elements appear just like you want them to! Automatically constrains forms at runtime, at the size used in designtime! You could say this one enables constraints at default, but WITH the ability to change it in designtime any way you like. Normally, setting constraints to any maxwidth etc, will not allow you to change your mind after that, unless you change the maxwidth etc again. This one lets you change it to any size you want in designtime, while keeping the constraints enabled in runtime! It is set to Active:= True by default, which, enables the component but can be set to Active:= False which disables it. With many thanks from the people at experts-exchange.com
Answer:
THellConstraints
Automatically constrains forms at runtime, at the size used in designtime! You could say this one enables constraints at default, but WITH the ability to change it in designtime any way you like. Normally, setting constraints to any maxwidth etc, will not allow you to change your mind after that, unless you change the maxwidth etc again. This one lets you change it to any size you want in designtime, while keeping the constraints enabled! It is set to Active:= True by default, which, enables the component but can be set to Active:= False which disables it.
HellConstraints.pas
//Open up THellConstraints7.dpk, after you have extracted all the files to your
//Lib directory, click compile and install, that is it!
unit HellConstraints;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls,
Menus, ExtCtrls;
type
THellconst = class(TComponent)
private
FActive :Boolean;
FOwner:TComponent;
procedure SetConstraints(Sender: TObject);
protected
procedure Loaded; override;
public
constructor Create(AOwner: TComponent); override;
published
property Active: boolean read FActive write FActive;
end;
procedure Register;
implementation
{$R thellconstraints.dcr}
procedure Register;
begin
RegisterComponents('Fdehell', [THellconst]);
end;
constructor THellconst.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FActive := True;
if (AOwner is TForm) then
FOwner := AOwner;
end;
procedure THellconst.Loaded ;
begin
Inherited Loaded ;
if not ( csDesigning in ComponentState ) then begin
if Assigned(FOwner) then
SetConstraints(FOwner);
end;
end;
procedure THellconst.SetConstraints(Sender: TObject);
begin
if FActive then
with (Sender as TForm).Constraints do begin
MaxWidth := (Sender as TForm).Width;
MaxHeight := (Sender as TForm).Height;
MinWidth := (Sender as TForm).Width;
MinHeight := (Sender as TForm).Height;
end;
end;
end.
{*******************************************************}
HellConstraints7.dpk
package HellConstraints7;
{$R *.res}
{$ALIGN 8}
{$ASSERTIONS ON}
{$BOOLEVAL OFF}
{$DEBUGINFO ON}
{$EXTENDEDSYNTAX ON}
{$IMPORTEDDATA ON}
{$IOCHECKS ON}
{$LOCALSYMBOLS ON}
{$LONGSTRINGS ON}
{$OPENSTRINGS ON}
{$OPTIMIZATION ON}
{$OVERFLOWCHECKS OFF}
{$RANGECHECKS OFF}
{$REFERENCEINFO ON}
{$SAFEDIVIDE OFF}
{$STACKFRAMES OFF}
{$TYPEDADDRESS OFF}
{$VARSTRINGCHECKS ON}
{$WRITEABLECONST OFF}
{$MINENUMSIZE 1}
{$IMAGEBASE $400000}
{$DESCRIPTION 'Automatically constraints the form at runtime, to the size set at designtime'}
{$LIBSUFFIX '7'}
{$IMPLICITBUILD OFF}
requires
rtl,
vcl;
contains
HellConstraints in 'HellConstraints.pas';
end.
{*******************************************************}