Delphi-页面控件中已打开的选项卡 [英] Delphi - Already opened tab in pagecontrol

查看:79
本文介绍了Delphi-页面控件中已打开的选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是关于带有动态选项卡的PageControl的。我有5个按钮(Button1,Button2,Button3,Button4,Button5)。

This is about PageControl with dynamic tabs. I have 5 buttons (Button1, Button2, Button3, Button4, Button5).

我想要以下内容:


  1. 每次单击按钮都会打开一个新的 TtabSheet

  2. 单击同一按钮时,应再次显示已打开的 Ttabsheet。

如何执行此操作?

推荐答案

我不知道您为什么真正想要五个按钮来完成创建选项卡然后选择它们的工作,但这是一个您可以尝试使用的方法

I don't know why you really want to have five buttons doing the job of creating the tabs and then selecting them, but this is one of the approaches you can try

uses System.Generics.Collections;

...

var
Newtabsheet: Ttabsheet;
Tabs: TList<Ttabsheet>;
Index: array[1..5] of Integer;
Ex: array [1..5] of Boolean;

implementation

将此内容放入 Formcreate 处理程序

procedure TForm6.FormCreate(Sender: TObject);
begin
Tabs := Tlist<Ttabsheet>.create;
for I=1 to 5 do ex[I]:=false;
end;

每个 OnClickButton 事件处理程序上的

procedure TForm6.Button1Click(Sender: TObject);
begin
if not(Ex[1])then
  begin
  Newtabsheet := Ttabsheet.Create(PageControl1);
  NewTabSheet.PageControl := PageControl1;
  Newtabsheet.Caption := 'Tab 1';
  Index[1] := Tabs.Count;
  Tabs.Add(Newtabsheet);
  Ex[1] := true;
  end
else
  begin
  Pagecontrol1.ActivePage := Tabs.List[Index[1]];
  end;
end;

procedure TForm6.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Tabs.Free;
end;

记住要更改数字。

它在RAD工作室Seattle上进行了测试。

It is tested on RAD studio Seattle.

注意:基于我编辑过答案的大卫评论。有关详细说明,请参见问题

Note: based on david comments I have edited my answer. and for further explanation please see this question

这篇关于Delphi-页面控件中已打开的选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆