2008. július 15., kedd

Use a TPanel as a host for child windows (MDI simulation) (2)


Problem/Question/Abstract:

Does anyone know if it is possible to change the Parent of the Mainform's client window in such a way that MDI forms are correctly displayed within (for instance) a panel?

Answer:

Here is a class that we use to place forms in panels:

unit oSubForm;

interface

uses
  Forms, Controls;

type
  TSubForm = class(TForm)
  public
    procedure CreateParams(var Params: TCreateParams); override;
    { ... }
    function SetUp: boolean; virtual;
    function Activate: boolean; virtual;
    function Deactivate: boolean; virtual;
    function Validate: boolean; virtual;
    function AddKnockOnChanged(Sender: TObject): boolean; virtual;
    { ... }
    procedure SetAllChanged; virtual;
  end;

type
  TDfEE_Form = class(TForm)
  private
  protected
  public
    function PageValidate(nPage: integer): boolean; virtual;
  published
  end;

implementation

uses
  WinTypes;

procedure TSubForm.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  with Params do
  begin
    WndParent := TWinControl(Owner).Handle;
    Params.Style := WS_CHILD or WS_CLIPSIBLINGS or WS_CLIPCHILDREN;
  end;
  Align := alClient;
  Parent := TWinControl(Owner);
end;

function TSubForm.SetUp: boolean;
begin
end;

function TSubForm.Activate: boolean;
begin
end;

function TSubForm.Deactivate: boolean;
begin
end;

procedure TSubForm.SetAllChanged;
begin
end;

function TSubForm.Validate: boolean;
begin
end;

function TSubForm.AddKnockOnChanged(Sender: TObject): boolean;
begin
end;

function TDfEE_Form.PageValidate(nPage: integer): boolean;
begin
  result := True;
end;

end.

Nincsenek megjegyzések:

Megjegyzés küldése