Форма является дочерней для панели

{codecitation class=»brush: pascal; gutter: false;» width=»600px»}

Автор: Xavier Pacheco

{

Copyright © 1998 by Delphi 4 Developer’s Guide — Xavier Pacheco and Steve Teixeira

}

unit NewChildFrm;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

ChildFrm, ExtCtrls;

type

TNewChildForm = class(TChildForm)

Image1: TImage;

private

{ Private declarations }

public

{ Public declarations }

end;

var

NewChildForm: TNewChildForm;

implementation

{$R *.DFM}

end.

{

Copyright © 1999 by Delphi 5 Developer’s Guide — Xavier Pacheco and Steve Teixeira

}

unit ChildFrm;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls,

Forms, Dialogs, StdCtrls, ExtCtrls, Menus;

type

TChildForm = class(TForm)

private

FAsChild: Boolean;

FTempParent: TWinControl;

protected

procedure CreateParams(var Params: TCreateParams); override;

procedure Loaded; override;

public

constructor Create(AOwner: TComponent); overload; override;

constructor Create(AOwner: TComponent; AParent: TWinControl); reintroduce;

overload;

// The method below must be overridden to return either the main menu

// of the form, or nil.

function GetFormMenu: TMainMenu; virtual; abstract;

function CanChange: Boolean; virtual;

end;

var

ChildForm: TChildForm;

implementation

{$R *.DFM}

constructor TChildForm.Create(AOwner: TComponent);

begin

FAsChild := False;

inherited Create(AOwner);

end;

constructor TChildForm.Create(AOwner: TComponent; AParent: TWinControl);

begin

FAsChild := True;

FTempParent := aParent;

inherited Create(AOwner);

end;

procedure TChildForm.Loaded;

begin

inherited;

if FAsChild then

begin

align := alClient;

BorderStyle := bsNone;

BorderIcons := [];

Parent := FTempParent;

Position := poDefault;

end;

end;

procedure TChildForm.CreateParams(var Params: TCreateParams);

begin

inherited CreateParams(Params);

if FAsChild then

Params.Style := Params.Style or WS_CHILD;

end;

function TChildForm.CanChange: Boolean;

begin

Result := True;

end;

end.

{

Copyright © 1999 by Delphi 5 Developer’s Guide — Xavier Pacheco and Steve Teixeira

}

unit MainFrm;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

StdCtrls, ExtCtrls, NewChildFrm;

type

TMainForm = class(TForm)

pnlMain: TPanel;

Splitter1: TSplitter;

pnlParent: TPanel;

btnNormal: TButton;

btnChild: TButton;

btnFree: TButton;

procedure btnNormalClick(Sender: TObject);

procedure btnChildClick(Sender: TObject);

procedure btnFreeClick(Sender: TObject);

private

FNewChildForm: TNewChildForm;

public

{ Public declarations }

end;

var

MainForm: TMainForm;

implementation

{$R *.DFM}

procedure TMainForm.btnNormalClick(Sender: TObject);

var

LocalChildForm: TNewChildForm;

begin

LocalChildForm := TNewChildForm.Create(Application);

try

LocalChildForm.ShowModal;

finally

LocalChildForm.Free;

end;

end;

procedure TMainForm.btnChildClick(Sender: TObject);

begin

if not Assigned(FNewChildForm) then

begin

FNewChildForm := TNewChildForm.Create(Application, pnlParent);

FNewChildform.Show;

pnlParent.Height := pnlParent.Height — 1;

end;

end;

procedure TMainForm.btnFreeClick(Sender: TObject);

begin

if Assigned(FNewChildForm) then

begin

FNewChildForm.Free;

FNewChildform := nil;

end;

end;

end.

Скачать весь проект

{/codecitation}

Добавить комментарий