W
wander8848
Unregistered / Unconfirmed
GUEST, unregistred user!
以前多用MDI,后来觉得让用户在多个子窗体之间切换不太方便,就想将子窗体dock到pangecontrol里面显示,子窗体为normal,主窗体为MDIform,有几个问题无法解决:
1、窗体dock到pangecontrol后,里面的edit文本框内无法用鼠标点击,但可以设置setfocus。
2、标题栏为灰。
2、在频繁的关闭、打开窗体操作下,偶尔会出现内存泄漏错误,为何?
3、同样的代码用Trzpagecongtrol怎么不行。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls, RzTabs;
type
TMainForm = class(TForm)
Panel1: TPanel;
Splitter1: TSplitter;
btn_Addchildform: TButton;
btn_Addchildform2: TButton;
PageControl1: TPageControl;
procedure CloseChildForm(sender:Tobject;var Action: TCloseAction );
procedure btn_AddchildformClick(Sender: TObject);
procedure PageControl1Change(Sender: TObject);
procedure btn_Addchildform2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
uses unit2,unit3;
procedure TMainForm.btn_AddchildformClick(Sender: TObject);
begin
if not assigned(childForm) then
begin
childForm:=TchildForm.Create(self);
childForm.Show;
end else
begin
pagecontrol1.ActivePage:=Ttabsheet(childForm.Parent );
exit;
end;
with TTabSheet.Create(PageControl1)do
begin
PageControl:= PageControl1;
Caption := childform.Caption;
PageControl.ActivePage:=PageControl.Pages[PageControl1.PageCount-1];
childForm.Parent:=PageControl1.ActivePage;
childForm.Edit1.Text:=inttostr(pageindex);
end;
childForm.OnClose := CloseChildForm;
end;
procedure TMainForm.PageControl1Change(Sender: TObject);
begin
ShowWindow(PageControl1.ActivePage.tag,SW_SHOWNORMAL);
SetactiveWindow(PageControl1.ActivePage.tag);
Caption:=inttostr(PageControl1.ActivePage.tag);
end;
procedure TMainForm.CloseChildForm(sender:Tobject;var Action: TCloseAction );
begin
ttabsheet(Tform(sender).Parent).PageControl:=nil;
ttabsheet(Tform(sender).Parent).Free;
end;
procedure TMainForm.btn_Addchildform2Click(Sender: TObject);
begin
if not assigned(childForm2) then
begin
childForm2:=TchildForm2.Create(self);
childForm2.Show;
end else
begin
pagecontrol1.ActivePage:=Ttabsheet(childForm2.Parent );
exit;
end;
with TTabSheet.Create(PageControl1)do
begin
PageControl:= PageControl1;
Caption := childform2.Caption;
PageControl.ActivePage:=PageControl.Pages[PageControl1.PageCount-1];
childForm2.Parent:=PageControl1.ActivePage;
childForm2.Edit1.Text:=inttostr(pageindex);
end;
childForm2.OnClose := CloseChildForm;
end;
end.
1、窗体dock到pangecontrol后,里面的edit文本框内无法用鼠标点击,但可以设置setfocus。
2、标题栏为灰。
2、在频繁的关闭、打开窗体操作下,偶尔会出现内存泄漏错误,为何?
3、同样的代码用Trzpagecongtrol怎么不行。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls, RzTabs;
type
TMainForm = class(TForm)
Panel1: TPanel;
Splitter1: TSplitter;
btn_Addchildform: TButton;
btn_Addchildform2: TButton;
PageControl1: TPageControl;
procedure CloseChildForm(sender:Tobject;var Action: TCloseAction );
procedure btn_AddchildformClick(Sender: TObject);
procedure PageControl1Change(Sender: TObject);
procedure btn_Addchildform2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
uses unit2,unit3;
procedure TMainForm.btn_AddchildformClick(Sender: TObject);
begin
if not assigned(childForm) then
begin
childForm:=TchildForm.Create(self);
childForm.Show;
end else
begin
pagecontrol1.ActivePage:=Ttabsheet(childForm.Parent );
exit;
end;
with TTabSheet.Create(PageControl1)do
begin
PageControl:= PageControl1;
Caption := childform.Caption;
PageControl.ActivePage:=PageControl.Pages[PageControl1.PageCount-1];
childForm.Parent:=PageControl1.ActivePage;
childForm.Edit1.Text:=inttostr(pageindex);
end;
childForm.OnClose := CloseChildForm;
end;
procedure TMainForm.PageControl1Change(Sender: TObject);
begin
ShowWindow(PageControl1.ActivePage.tag,SW_SHOWNORMAL);
SetactiveWindow(PageControl1.ActivePage.tag);
Caption:=inttostr(PageControl1.ActivePage.tag);
end;
procedure TMainForm.CloseChildForm(sender:Tobject;var Action: TCloseAction );
begin
ttabsheet(Tform(sender).Parent).PageControl:=nil;
ttabsheet(Tform(sender).Parent).Free;
end;
procedure TMainForm.btn_Addchildform2Click(Sender: TObject);
begin
if not assigned(childForm2) then
begin
childForm2:=TchildForm2.Create(self);
childForm2.Show;
end else
begin
pagecontrol1.ActivePage:=Ttabsheet(childForm2.Parent );
exit;
end;
with TTabSheet.Create(PageControl1)do
begin
PageControl:= PageControl1;
Caption := childform2.Caption;
PageControl.ActivePage:=PageControl.Pages[PageControl1.PageCount-1];
childForm2.Parent:=PageControl1.ActivePage;
childForm2.Edit1.Text:=inttostr(pageindex);
end;
childForm2.OnClose := CloseChildForm;
end;
end.