Delphi:RzPageControl(pagecontrol)实现多标签的动态添加,切换,关闭

本文介绍如何利用RzPageControl组件在应用程序中实现多标签页功能,包括跳转、关闭标签页以及通过标题判断标签页是否已打开等操作。
 

使用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;

Raize Components 6.1.12 Modifications The following is a list of all of the modifications that have been made for version 6.1.12 of Raize Components. For a list of all modifications made to previous versions of Raize Components 6, please see the "RC 6 Modifications.txt" file. -------------------------------------------------------------------------------- Build: 6.1.12 Date: 11 Apr 2015 -------------------------------------------------------------------------------- Added support for Embarcadero RAD Studio XE8. Supported IDEs Embarcadero RAD Studio XE8 -- Delphi XE8 & C++Builder XE8 Embarcadero RAD Studio XE7 -- Delphi XE7 & C++Builder XE7 Embarcadero RAD Studio XE6 -- Delphi XE6 & C++Builder XE6 Embarcadero RAD Studio XE5 -- Delphi XE5 & C++Builder XE5 Embarcadero RAD Studio XE4 -- Delphi XE4 & C++Builder XE4 Embarcadero RAD Studio XE3 -- Delphi XE3 & C++Builder XE3 Embarcadero RAD Studio XE2 -- Delphi XE2 & C++Builder XE2 Embarcadero RAD Studio XE -- Delphi XE & C++Builder XE Embarcadero RAD Studio 2010 -- Delphi 2010 & C++Builder 2010 CodeGear RAD Studio 2009 -- Delphi 2009 & C++Builder 2009 RzButton.pas * Fixed issue in TRzToolButton where drop down menu would be displayed on the adjacent monitor under certainly situations. RzDBEdit.pas * Fixed issue in TRzDBEdit and descendants where registered style hook was not correctly unregistered when the hook was no longer needed. * Added UseFormatToParse property to TRzDateTimeEdit. Set this property to True in situations where the Time to be parsed contains more elements than are contained in the LongTimeFormat string. For example, if the Time needed to be entered must have 'hh:nn:ss.zzz' and the LongTimeFormat string is set to 'hh:nn', then set the UseFormatToParse to True and set the Format property to the desired format string. RzDBList.pas * Surface the Sorted property in TRzDBListBox. RzEdit.pas * Fixed issue in TRzEdit and descendants where registered style hook was not correctly unregistered when the hook was no longer needed. * Added UseFormatToParse property to TRzDateTimeEdit. Set this property to True in situations where the Time to be parsed contains more elements than are contained in the LongTimeFormat string. For example, if the Time needed to be entered must have 'hh:nn:ss.zzz' and the LongTimeFormat string is set to 'hh:nn', then set the UseFormatToParse to True and set the Format property to the desired format string. RzGroupBar.pas * Fixed issue in TRzGroupBar where registered style hook was not correctly unregistered when the hook was no longer needed. RzLstBox.pas * Fixed issue in TRzListBox and descendants where text in item hints would get clipped if the TRzBalloonHints component was also being used in the application. RzShellCtrls.pas * When dragging a file from a TRzShellList and dropping it onto a different folder in the associated TRzShellTree, the shell tree no longer scrolls to the source folder represented by the shell list. That is, the shell tree maintains its current view. RzSpnEdt.pas * Fixed issue where ParentColor property in TRzSpinner and TRzDBSpinner was not getting streamed correctly to form files. RzTabs.pas * Fixed issue where drop-down menu in TRzPageControl and TRzTabControl would not be displayed correctly when using a custom VCL Style in XE6 or XE7. * Added LightenUnselectedColoredTabs property to TRzPageControl and TRzTabControl. When this property is True, a non-active colored tab will be displayed with a lightened version of the tab color. When this property is False, the unselected tab is displayed in the same color as the active tab color. --------------------------------------------------------------------------------
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值