使用RzPageControl来实现多标签页
使用菜单来打开标签页,通过标签页的caption来判断将标签页是否已经被打开过了.

1.创建标签页,并判断是否是已经打开过的页面

 

procedure TFmain.Page1Click(Sender: TObject);
var
newpage:TRzTabSheet;
index:integer;
begin
newpage:=nil;
if not gotopage('第一页',newpage) then
begin
index:=findpage('第一页');
if index=-1 then exit;
Form1:=TForm.Create(nil);
Form1.Parent:=Fmain.pagecontrol1.Pages[index];
Form1.Align:=alclient;
Form1.BorderStyle:=bsnone;
Form1.Show;
end;
end;

 

gotopage函数,跳转到需要显示的那页,不存在的话就创建那一页

{
gotopage:跳转到某页
如果存在这页,跳转后返回true;
如果不存在,则新建一页,返回false;
}
function TFmain.gotopage(scaption:string;newpage:TRzTabSheet):boolean;
var
i:integer;
isExists:Boolean;
begin
newpage:=nil;
isExists:=false;
if length(scaption)<=0 then exit;
for i:=0 to pagecontrol1.PageCount-1 do
begin
if pagecontrol1.Pages[i].Caption=scaption then
begin
pagecontrol1.ActivePage:=pagecontrol1.Pages[i];
isExists:=true;
break;
end;
end;
if not isExists then
begin
newpage:=TRZTabSheet.Create(pagecontrol1);
newpage.Caption:=scaption;
newpage.PageControl:=pagecontrol1;
pagecontrol1.ActivePage:=newpage;
end;
result:=isExists;
end;

findpage函数,找到指定caption的那一页,返回那页的index,如果那页不存在,返回-1

{
findpage:根据标题查询页,返回index
参数为页caption
没有找到返回-1,找到返回index
}
function TFmain.findpage(scaption:string):integer;
var
i:integer;
isExists:boolean;
begin
isExists:=false;
for i:=0 to pagecontrol1.PageCount-1 do
begin
if pagecontrol1.Pages[i].Caption=scaption then
begin
pagecontrol1.ActivePage:=pagecontrol1.Pages[i];
isExists:=true;
result:=i;
break;
end;
end;
if not isExists then result:=-1;
end;


2.双击标签,关闭标签页
RzpageControl的双击事件,如果标题不是’首页’就关闭当前显示的这页

procedure TFmain.PageControl1DblClick(Sender: TObject);
begin
if PageControl1.ActivePage.Caption<>'首页' then
pagecontrol1.CloseActiveTab;
end;


3.通过关闭按钮关闭
先设置ShowCloseButton属性为true
然后重写OnClose事件

procedure TFmain.PageControl1Close(Sender: TObject;
var AllowClose: Boolean);
begin //如果只剩下一页不关闭,或当前页是首页不关闭
if (self.PageControl1.PageCount=1) or (self.PageControl1.ActivePage.Caption='首页') then
begin
AllowClose:=False;
Exit;
end;
AllowClose:=True;
end;

Delphi中TRzPageControl实现多窗口的融合窗口
procedure ShowDockForm(FormClass: TFormClass; dockCtrl: TWinControl;
IsMaxed: Boolean);

procedure ShowCaption(ParentCtrl:TWinControl;ACaption:string);
begin
   if ParentCtrl is TRzTabSheet then
    TRzTabSheet(ParentCtrl).Caption := ACaption;
end;

var
i: Integer;
TabCtrl:TRzTabSheet;
Form:TForm;
begin
Screen.Cursor := crHourGlass;
try
   for i := 0 to Screen.CustomFormCount - 1 do
     if Screen.CustomForms[i] is FormClass then
     begin
       if (not (Screen.CustomForms[i]).Visible) then
         (Screen.CustomForms[i]).Visible := True;
       (Screen.CustomForms[i]).BringToFront;
       (Screen.CustomForms[i]).SetFocus;
       TabCtrl := TRzTabSheet(Screen.CustomForms[i].Parent);
       ShowCaption(TabCtrl,Screen.CustomForms[i].Caption);
       TRzPageControl(dockCtrl).ActivePageIndex := TabCtrl.PageIndex;
         exit;
     end;

   TabCtrl := TRzTabSheet.Create(dockCtrl);   //dockCtrl
   TabCtrl.PageControl := TRzPageControl(dockCtrl);
   TRzPageControl(dockCtrl).ActivePageIndex := TabCtrl.PageIndex;

   Form := FormClass.Create(TabCtrl);
   with Form do
   try
     ManualDock(TabCtrl);
     ShowCaption(TabCtrl,Caption);

     Show;
     Form.WindowState := wsMaximized;
     Form.Align := alClient;
   except
     Free;
   end;
  
finally
   Screen.Cursor := crDefault;
end;
end;