使用菜单来打开标签页,通过标签页的caption来判断将标签页是否已经被打开过了.
1.创建标签页,并判断是否是已经打开过的页面
procedure Form1.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.rzpgcntrl1.Pages[index];
Form1.Align:=alclient;
Form1.BorderStyle:=bsnone;
Form1.Show;
end;
end;
gotopage函数,跳转到需要显示的那页,不存在的话就创建那一页
{
gotopage:跳转到某页
如果存在这页,跳转后返回true;
如果不存在,则新建一页,返回false;
}
function
Form1.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 rzpgcntrl1.PageCount-1 do
begin
if
rzpgcntrl1.Pages[i].Caption=scaption then
begin
rzpgcntrl1.ActivePage:=rzpgcntrl1.Pages[i];
isExists:=true;
break;
end;
end;
if not isExists then
begin
newpage:=TRZTabSheet.Create(rzpgcntrl1);
newpage.Caption:=scaption;
newpage.PageControl:=rzpgcntrl1;
rzpgcntrl1.ActivePage:=newpage;
end;
result:=isExists;
end;
findpage函数,找到指定caption的那一页,返回那页的index,如果那页不存在,返回-1
{
findpage:根据标题查询页,返回index
参数为页caption
没有找到返回-1,找到返回index
}
function Form1.findpage(scaption:string):integer;
var
i:integer;
isExists:boolean;
begin
isExists:=false;
for i:=0 to rzpgcntrl1.PageCount-1 do
begin
if
rzpgcntrl1.Pages[i].Caption=scaption then
begin
rzpgcntrl1.ActivePage:=rzpgcntrl1.Pages[i];
isExists:=true;
result:=i;
break;
end;
end;
if not isExists then result:=-1;
end;
2.双击标签,关闭标签页
RzpageControl的双击事件,如果标题不是’首页’就关闭当前显示的这页
procedure Form1.rzpgcntrl1DblClick(Sender: TObject);
begin
if
rzpgcntrl1.ActivePage.Caption<>'首页'
then
rzpgcntrl1.CloseActiveTab;
end;
3.通过关闭按钮关闭
先设置ShowCloseButton属性为true
然后重写OnClose事件
procedure Form1.rzpgcntrl1Close(Sender: TObject;
var AllowClose: Boolean);
begin //如果只剩下一页不关闭,或当前页是首页不关闭
if (self.rzpgcntrl1.PageCount=1) or
(self.rzpgcntrl1.ActivePage.Caption='首页')
then
begin
AllowClose:=False;
Exit;
end;
AllowClose:=True;
end;
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。