terry584 Posted May 31, 2013 Share Posted May 31, 2013 (edited) ; This is an example of creating and controlling AutoIT TABs with a Button. ; ; This program creates 3 Tabs with controls on Tabs 1 and 2. ; The main form has a "Next TAB" button which works, but ; the controls do not show up properly when a new Tab is selected. expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiTab.au3> $GUI = GUICreate("Tab Control Example #1", 300, 200) $hTab = GUICtrlCreateTab(20, 10, 260, 150) $Tab1 = GUICtrlCreateTabItem("Tab1") $Tab2 = GUICtrlCreateTabItem("Tab2") $Tab3 = GUICtrlCreateTabItem("Tab3") GUICtrlCreateTabItem("") $Switch_Button = GUICtrlCreateButton("Next TAB", 20, 170, 80, 20) ; $Switch_Button = 7 GUISetState(@SW_SHOW, $GUI) ; This code is commented out, but is an interesting example. ; This code is an example of how to cause the 2nd Tab to be selected at startup. ; $iCurrent_TabIndex = _GUICtrlTab_GetCurSel($hTab) ; $iNext_TabIndex = $iCurrent_TabIndex ; $iNext_TabIndex += 1 ; _GUICtrlTab_SetCurSel($hTab, $iNext_TabIndex) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ; $GUI_EVENT_CLOSE = -3 Exit Case $Switch_Button MsgBox(0, "Test", GUIGetMsg(), 1) $iCurrent_TabIndex = _GUICtrlTab_GetCurSel($hTab) $iNext_TabIndex = $iCurrent_TabIndex Switch $iCurrent_TabIndex Case 0, 1 $iNext_TabIndex += 1 Case 2 $iNext_TabIndex = 0 EndSwitch _GUICtrlTab_SetCurSel($hTab, $iNext_TabIndex) EndSwitch WEnd Edited May 31, 2013 by Melba23 Added code tags Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 31, 2013 Moderators Share Posted May 31, 2013 terry584,Welcome to the AutoIt forum. Is this just an example or do you have a problem with this code? M23P.S. When you post code in future please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
terry584 Posted June 1, 2013 Author Share Posted June 1, 2013 Thank you Melba23 for cleaning up my code! The following is a working version of what I was trying to accomplish. It does not change tabs with the mouse wheel, but that was not my aim. ; This code is an example of creating and controlling AutoIT TABs with two Buttons. ; ; This program creates 3 Tabs with controls on Tabs 1 and 2. ; The main form has a two button which noew works. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GuiTab.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <TabConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=Tab_Control_Ex_1.kxf Global $GUI = GUICreate("Tab Control Example #1", 563, 360, 192, 125) ; The following $ctrlTab was originally $hTab before I added the ControlGetHandle command line. Global $ctrlTab = GUICtrlCreateTab(20, 10, 508, 294) Global $hTab = ControlGetHandle($GUI, "", $ctrlTab) $Tab1 = GUICtrlCreateTabItem("Tab1") $My_1st_Input = GUICtrlCreateLabel("My_1st_Input", 32, 72, 68, 18) $Input1 = GUICtrlCreateInput("Input1", 106, 70, 169, 22) ; Close Tab definiton GUICtrlCreateTabItem("") $Tab2 = GUICtrlCreateTabItem("Tab2") $Tab2_Label = GUICtrlCreateLabel("Tab2_Label", 57, 66, 60, 18) ; Close Tab definiton GUICtrlCreateTabItem("") $Tab3 = GUICtrlCreateTabItem("Tab3") ; Close Tab definiton GUICtrlCreateTabItem("") $Next_Button = GUICtrlCreateButton("Next TAB", 220, 322, 80, 20) $Prev_Button = GUICtrlCreateButton("Previous TAB", 130, 322, 80, 20) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### For $n = 0 To 2 ; Demonstrate that all tabs CAN be selected Sleep(1000) _GUICtrlTab_ClickTab($hTab, $n) Next $n = -1 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ; $GUI_EVENT_CLOSE = -3 Exit Case $Next_Button ; The following line is needed to sense when the operator has clicked on a TAB. ; The number of the CURRENT TAB is stored $n. ; Note, 0 = Tab1, 1 = Tab2, 2 = Tab3 $n = _GUICtrlTab_GetCurSel($hTab) Switch $n Case -1 $n = 0 Case 0, 1 ; This means Case = 0 OR Case = 1 $n += 1 Case 3 $n = 2 EndSwitch ; This ClickTab command causes the desired TAB to be selected ; AND it also causes the controls on the TAB to be REDRAWN (Refreshed). _GUICtrlTab_ClickTab($hTab, $n) Case $Prev_Button ; The following line is needed to sense when the operator has clicked on a TAB. ; The number of the CURRENT TAB is stored $n. ; Note, 0 = Tab1, 1 = Tab2, 2 = Tab3 $n = _GUICtrlTab_GetCurSel($hTab) Switch $n Case -1 $n = 0 Case 1, 2 ; This means Case = 1 OR Case = 2 $n -= 1 Case 0 $n = 0 EndSwitch ; This ClickTab command causes the desired TAB to be selected ; AND it also causes the controls on the TAB to be REDRAWN (Refreshed). _GUICtrlTab_ClickTab($hTab, $n) EndSwitch WEnd Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 1, 2013 Moderators Share Posted June 1, 2013 terry584, Here is how I would code it: expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> Global $aTab[3] $hGUI = GUICreate("Tab Control Example #1", 300, 200) $cTab = GUICtrlCreateTab(20, 10, 260, 150) $aTab[0] = GUICtrlCreateTabItem("Tab 0") $aTab[1] = GUICtrlCreateTabItem("Tab 1") $aTab[2] = GUICtrlCreateTabItem("Tab 2") GUICtrlCreateTabItem("") $cNext_Button = GUICtrlCreateButton("Next TAB", 20, 170, 80, 20) $cPrev_Button = GUICtrlCreateButton("Prev TAB", 120, 170, 80, 20) GUISetState() GUIRegisterMsg($WM_MOUSEWHEEL, "_WM_MOUSEWHEEL") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cNext_Button _Next_Tab() Case $cPrev_Button _Prev_Tab() EndSwitch WEnd Func _Next_Tab() $iCurr_Tab = GUICtrlRead($cTab) $iNext_Tab = Mod(GUICtrlRead($cTab) + 1, UBound($aTab)) GUICtrlSetState($aTab[$iNext_Tab], $GUI_SHOW) EndFunc Func _Prev_Tab() $iCurr_Tab = GUICtrlRead($cTab) $iPrev_Tab = $iCurr_Tab - 1 If $iPrev_Tab = -1 Then $iPrev_Tab = UBound($aTab) - 1 EndIf GUICtrlSetState($aTab[$iPrev_Tab], $GUI_SHOW) EndFunc Func _WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $lParam Local $iDelta = BitShift($wParam, 16) ; Mouse wheel movement Select Case $iDelta = 0 ; Do nothing Case $iDelta > 0 _Next_Tab() Case $iDelta < 0 _Prev_Tab() EndSelect Return $GUI_RUNDEFMSG EndFunc ;==>_WM_MOUSEWHEEL And the mousewheel works too. Please ask if you have any questions. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
terry584 Posted June 1, 2013 Author Share Posted June 1, 2013 Melba23, your code example is clean, powerful, and helpful. Thanks again! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 1, 2013 Moderators Share Posted June 1, 2013 terry584,My pleasure. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now