如何在TTabcontrol中隐藏多个选项卡 [英] How to hide multiple tabs in TTabcontrol
问题描述
我的程序有3个下拉菜单和1个ttabcontrol,其中有5个选项卡。我需要知道的是,如果下拉菜单选择了特定项目,如何隐藏所有选项卡并再次设置其可见性。
例如
我的下拉列表的索引项为。
A,B,C,A + B,A + C
TabControl具有以下选项卡。
A B C
现在,我需要隐藏所有选项卡,如果下拉菜单选择了a或& ;,则取消隐藏选项卡A。 b如果将下拉列表选择为A + B。
My program has three drop-down and one ttabcontrol which has 5 Tabs. what i need to know is how can i hide all the tabs and set their visiblety back again if drop-down menu has a particular item selected. For example My drop-down has index item of. A , B , C , A+B , A+C TabControl had following tabs. A B C Now i need to hide all the tabs and unhide tab A if drop down has selected a or a & b if dropdown is Selected to A+ B.
推荐答案
使用可枚举类型进行操作。您可以非常轻松地探索布尔操作。
use enumerable type to do that. You can explore boolean operation very easy.
TYPE
TabControlTag = (A, B, C);
TabTags = set of TabControlTag;
TForm1=class(TForm)
...
实施
procedure TForm1.HideTabControl(Sender: TObject);
{hide all tabItem in tabControl}
var
i: integer;
begin
for i := 0 to TabControl1.ComponentCount - 1 do
if TabControl1.Components[i] is TTabItem then
with TabControl1.Components[i] do
begin
visible := false;
end;
end;
如果您使用 TCombobox
作为下拉列表,请使用 OnChange
事件
if you are using TCombobox
as dropDown list, use the OnChange
event
procedure TForm1.ComboBox1Change(Sender: TObject);
var
Tabs: TabTags;
begin
case ComboBox1.ItemIndex of
0: { A } Tabs := [A];
1: { B } Tabs := [B];
2: { C } Tabs := [C];
3: { A+B } Tabs := [A,B];
4: { A+C } Tabs := [A,C];
end;
if A in Tabs then tabItem1.Visible:=true;
if B in Tabs then tabItem2.Visible:=true;
if C in Tabs then tabItem3.Visible:=true;
end;
一个非常灵活且可扩展的解决方案。
A very flexible and expansible solution.
例如,使用 TCheckbox
var
Tabs: TabTags;
begin
tabs:=[];
If checkBoxA.IsChecked then TabTags:= [A];
If checkBoxB.IsChecked then TabTags:= TabTags + [B];//OR boolean operations. Also allowed [A,B] * [A] which means AND, [A,B] - [A] which means NOR,
If checkBoxC.IsChecked then Include(TabTags,C)
if A in Tabs then tabItem1.Visible:=true;
if B in Tabs then tabItem2.Visible:=true;
if C in Tabs then tabItem3.Visible:=true;
end
这篇关于如何在TTabcontrol中隐藏多个选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!