怎样对fsMDIChild窗口进行操作呀!(200分)

  • 主题发起人 主题发起人 zch619
  • 开始时间 开始时间
Z

zch619

Unregistered / Unconfirmed
GUEST, unregistred user!
fsMDIChild,在正常情况下关闭时只是最小化在父窗口的左下脚。怎样才可以将其关闭和在需要时打开呀?
请高手指点!
 
大家帮帮忙呀!
 
在主窗体里这样
if not Assigned(form3) then
begin
form3:=tform3.Create(Application, Panel1);
form3.Show;
end;
然后在子窗体中
procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=cafree;
form3:=nil;
end;

具体的你可参看delphi5程序员开发指南第四章的,那讲得很详细
 
在子窗口的OnClose事件中加:Action:=caFree;
就可以在关闭时把窗体释放掉

在需要时再打开,用以下代码:
 TFD022.Create(Application); // 子窗体建立
 
//新建:
XTWH_Frm := TXTWH_Frm.Create(Application);
//关闭一个
//包含Dbrf单元:
procedure TMainFrm.mn_closeClick(Sender: TObject);
Var
i : integer;
MDIfrm : tform;
begin
if not isnullid(XTWH_Frm) then //isnullid函数包含在DBRF中,具体用法看帮助
begin
MDIfrm := XTWH_Frm;
FreeAndNil(MDIfrm);
end;
end;
//在按钮中关闭所有子窗体:
procedure TMainFrm.mn_closeClick(Sender: TObject);
Var
i : integer;
MDIfrm : tform;
begin
while MainFrm.MDIChildCount > 0 do
for i := 0 to MainFrm.MDIChildCount - 1 do
begin
MDIfrm := MainFrm.MDIChildren;
FreeAndNil(MDIfrm);
end;
end;
 
谢谢大家的回答,我试试
 
在onclose里
action := cafree;
from1 := nil;
 
多人接受答案了。
 
建议动态创建子窗口,简单例子如下:
主窗体:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus;

type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
File1: TMenuItem;
new1: TMenuItem;
window1: TMenuItem;
Cascade1: TMenuItem;
procedure Cascade1Click(Sender: TObject);
procedure new1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

uses
Unit2;

procedure TForm1.Cascade1Click(Sender: TObject);
begin
Cascade
end;

procedure TForm1.new1Click(Sender: TObject);
var
Form2:TForm2;
begin
Form2 := TForm2.Create(Self);
Form2.Caption := TimeToStr(Now);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.WindowMenu := window1;
end;

end.

******************************************************************
子窗体:
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TForm2 = class(TForm)
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;

end.
 
后退
顶部