如何在TTabcontrol中隐藏多个选项卡

时间:2020-12-14 18:55:31

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.

我的程序有三个下拉菜单和一个ttabcontrol,有5个Tabs。我需要知道的是,如果下拉菜单中选择了特定项目,我如何隐藏所有选项卡并再次设置其可见性。例如,我的下拉列表的索引项为。 A,B,C,A + B,A + C TabControl有以下标签。 A B C现在我需要隐藏所有选项卡并取消隐藏选项卡A,如果下拉选择了a或a&b,如果下拉选择为A + B.

1 个解决方案

#1


-1  

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)
...

Implementation

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;

if you are using TCombobox as dropDown list, use the OnChange event

如果您使用TCombobox作为dropDown列表,请使用OnChange事件

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.

一个非常灵活和可扩展的解决方案。

For example, using TCheckbox

例如,使用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

#1


-1  

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)
...

Implementation

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;

if you are using TCombobox as dropDown list, use the OnChange event

如果您使用TCombobox作为dropDown列表,请使用OnChange事件

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.

一个非常灵活和可扩展的解决方案。

For example, using TCheckbox

例如,使用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