我的程序有三個下拉菜單和一個ttabcontrol,其中有5個選項卡。我需要知道的是如何隱藏所有選項卡並將其可見性設置回來,如果下拉菜單選擇了特定項目。 例如 我的下拉列表有索引項。 A,B,C,A + B,A + C TabControl有以下選項卡。 A B C 現在我需要隱藏所有標籤和取消隱藏標籤甲如果下拉已經選擇了或& B如果下拉被選擇爲A + B.如何隱藏TTabcontrol中的多個選項卡
回答
使用枚舉類型來做到這一點。您可以非常輕鬆地探索布爾操作。
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
事件
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;
一個非常靈活和可擴展的解決方案。
例如,使用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
瞭解更多關於可枚舉邏輯的信息請閱讀https://www.thoughtco.com/understanding-delphi-set-type-1057656 –
如果選擇標籤A + B或B + C,那麼如何選擇兩個標籤? – Buddy
這將工作正常!它已經在上面的程序中實現了!只需將組合框中的新項目與您想要的組合相結合,並在'Case of'結構中添加對此索引的引用,但這就是我建議您使用'TCheckBox'或'TCheckBoxList'的原因,然後將所有可能的組合 –
- 1. 如何隱藏TabActivity中的選項卡?
- 2. 如何隱藏Android選項卡布局中的選項卡?
- 3. 如何在ext4.1中隱藏選項卡?
- 4. 如何隱藏tabBarController的選項卡?
- 5. 從JTabbedPane隱藏選項卡
- 6. 隱藏jQuery選項卡
- 7. 隱藏UITabBarControllers選項卡
- 8. 選項卡式活動中的隱藏選項卡標題
- 9. 如何隱藏選項卡控制選項卡選擇在Visual Basic中
- 10. Flex:隱藏TabNavigator中的選項卡
- 11. 隱藏java中的選項卡標題
- 12. TabNavigator中的Flex隱藏選項卡
- 13. 如何隱藏100個網站上的SharePoint選項卡? (SP2010)
- 14. Weifenluo DockPanel中 - 隱藏選項卡控制
- 15. 隱藏多選框中的選項
- 16. 想要隱藏使用jQuery的選項卡(數據選項卡)?
- 17. 我被卡在javascript中,隱藏/激活選定的選項卡
- 18. 如何編程隱藏選項卡中的TabPanel(ExtJS的3)
- 19. 如何顯示/隱藏具有多個選擇選項的div
- 20. 如何隱藏ExtJS 4中的選項卡4
- 21. 如何隱藏JTabbedPane中的選項卡面板?
- 22. 如何隱藏選項卡控件中的標籤頁
- 23. 如何在extjs中隱藏選項卡的html內容?
- 24. 如何隱藏/阻止在C#中的選項卡?
- 25. 我們如何隱藏Android中的ActionBar選項卡?
- 26. 如何繞過隱藏選項卡中的setTimeout節流閥?
- 27. Bootstrap選項卡隱藏我的模型
- 28. Chart.js渲染隱藏的Bootsrap選項卡
- 29. 如何使用Jquery隱藏隱藏選項卡上的子元素,並隱藏它直至隱藏它?
- 30. Flex選項卡導航器:初始化隱藏選項卡
什麼其他2 *下拉* S在做什麼? –
在做同樣的事情D E F和G H我相同的A B C – Buddy
我的建議是首先使用條件語句來工作。例如「如果」。之後,你可能會考慮考慮如何更有效地完成它。 –