|
本帖最后由 sellkingfly 于 2017-9-5 16:15 编辑
请大家帮忙看下如何能隐藏某个tabitem,例如生成四个后的第二个。目的是保留该item的index
因为如果删除这个item整个的index就重新排列,动态生成item的时候其上的控件id就乱了。
多谢多谢!#include <GuiTab.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
#include <array.au3>
main()
Global $ad, $idFileItem3, $nMsg, $Form1, $idTab, $i, $j, $close
Func main()
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 721, 572, 505, 100)
Global $idTab = GUICtrlCreateTab(220, 40, 450, 300)
Global $create_tab = GUICtrlCreateButton('create tab', 20,30)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;_WinAPI_SetWindowTheme(GUICtrlGetHandle($TreeView1), 'Explorer') ;改变加号成三角号
Global $i = 1, $j = 200, $iCurrTab
Local $holder = '-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1';
Global $tab = StringSplit($holder, '|')
Global $bary = StringSplit($holder, '|')
Global $iary = StringSplit($holder, '|')
Global $close = StringSplit($holder, '|')
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $create_tab
addnum()
EndSwitch
;for excute button
For $ii = 1 To UBound($bary) - 1
If $bary[$ii] = $nMsg Then MsgBox(0, "", GUICtrlRead($nMsg) & @CR & GUICtrlRead($iary[$ii]))
Next
;for close button
For $ii = 1 To UBound($close) - 1
If $close[$ii] = $nMsg Then
;MsgBox(0,'',$nMsg)
$tabseq = StringReplace(GUICtrlRead($nMsg),'close ','')
$tabindex=_GUICtrlTab_FindTab($idTab,"addnum_" & $tabseq)
MsgBox(0,'',GUICtrlRead($nMsg)&@cr& $tabseq &@cr& $tabindex)
GUICtrlDelete($close[$tabseq])
GUICtrlDelete($bary[$tabseq])
GUICtrlDelete($iary[$tabseq])
_GUICtrlTab_DeleteItem ( $idTab, $tabindex)
EndIf
Next
WEnd
EndFunc ;==>main
Func addnum()
;MsgBox(0,'i=',$i)
$tab[$i] = GUICtrlCreateTabItem("addnum_" & $i)
$close[$i] = GUICtrlCreateButton("close " & $i, 230, 70, 80, 20)
$bary[$i] = GUICtrlCreateButton("button " & $i, 300, 100, 80, 20)
$iary[$i] = GUICtrlCreateInput("", 400, 100, 80, 20)
GUICtrlCreateTabItem("")
$i = $i + 1
EndFunc ;==>addnum
用button来模拟tab控件吧又遇到删除某个item后再生成新的item算位置比较乱。
另外当生成tabitem多时添加滚动条也挺复杂的,因此觉得隐藏tab控件的tabitem最简单。#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Example()
Func Example()
; Create a GUI with various controls.
Global $hGUI = GUICreate("Example",600,600,-1,-1)
Local $idOK = GUICtrlCreateButton("creat tab", 400, 460, 85, 25)
; Display the GUI.
GUISetState(@SW_SHOW, $hGUI)
Local $holder = '-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1';
Global $abutton = StringSplit($holder, '|')
Global $atab = StringSplit($holder, '|')
Global $aclose = StringSplit($holder, '|')
Global $i = 1
; Loop until the user exits.
While 1
$nMsg=GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
ExitLoop
Case $idOK
create_tab()
EndSwitch
For $ii=1 To UBound($abutton) - 1
If $abutton[$ii] = $nMsg Then
;MsgBox(0,'',GUICtrlRead($nMsg),-1,$hGUI)
WinActivate($atab[$ii])
EndIf
Next
For $ii =1 To UBound($aclose)-1
If $aclose[$ii]=$nMsg Then
MsgBox(0,'',GUICtrlRead($nMsg))
GUICtrlDelete($aclose[$ii])
GUICtrlDelete($abutton[$ii])
GUICtrlDelete($atab[$ii])
For $jj=$ii To $i-1
GUICtrlSetPos($abutton[$jj+1],60*($jj-1))
Next
;If $ii-1>0 Then WinActivate($atab[$ii-1])
;MsgBox(0,'',$ii&@CR&$i)
EndIf
Next
WEnd
; Delete the previous GUI and all controls.
GUIDelete($hGUI)
EndFunc ;==>Example
Func create_tab()
GUISwitch($hGUI)
$tabl = 590
$abutton[$i] =GUICtrlCreateButton('tab_' & $i,60*($i-1),10,60,20)
$atab[$i]=GUICreate("tab",$tabl,300,2,28,$WS_POPUPWINDOW,$WS_EX_MDICHILD ,$hGUI)
$aclose[$i] = GUICtrlCreateButton('close_'&$i,30,100,80,25)
GUISetState(@SW_SHOW,$atab[$i])
$i=$i+1
EndFunc
|
|