Jump to content

TabItems with close button


Floppy
 Share

Recommended Posts

  • Moderators

Floppy,

Yes - you can create and delete tabs in the same way as any other control. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Floppy,

You put a "Close" button in each tab - then the script knows which tab to close. Or you have a "Close button outside the tab structure and then close the active tab when it is pressed. Either will work - I tested before replying yesterday. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Floppy,

How about this: ;)

#include <GuiConstantsEx.au3>
#include <GuiTab.au3>
#include <StaticConstants.au3>
#include <Array.au3>

Global $aTab[5] = [4]

$hGUI = GUICreate("Test", 500, 500)

$cCloseX = GUICtrlCreateLabel("X", 0, 0, 1, 1, BitOR($SS_NOTIFY, $SS_CENTER, $SS_SUNKEN))
GUICtrlSetBkColor($cCloseX, 0xFF8080)

$cTab = GUICtrlCreateTab(5, 5, 390, 260)
$hTab = GUICtrlGetHandle($cTab)
For $i = 1 To $aTab[0]
    $aTab[$i] = GUICtrlCreateTabItem("Tab item - " & $i & " - X")
Next
GUICtrlCreateTabItem("")

TabEvent()

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cTab
            TabEvent()
        Case $cCloseX
            $iIndex = GUICtrlRead($cTab) + 1
            GUICtrlDelete($aTab[$iIndex])
            _ArrayDelete($aTab, $iIndex)
            $aTab[0] -= 1
            If $aTab[0] Then
                GUICtrlSetState($cCloseX, $GUI_SHOW)
            Else
                GUICtrlSetState($cCloseX, $GUI_HIDE)
            EndIf
    EndSwitch
WEnd

Func TabEvent()

    Local $iMargin_X = 6, $iMargin_Y = 6
    $iTab_Index = _GUICtrlTab_GetCurSel($hTab)
    $aTab_Coord = _GUICtrlTab_GetItemRect($hTab, $iTab_Index)
    $iOffset = $aTab_Coord[2] - $aTab_Coord[0] - 20
    GUICtrlSetPos($cCloseX, $iMargin_X + $aTab_Coord[0] + $iOffset, $iMargin_Y + $aTab_Coord[1], 20, $aTab_Coord[3] - $aTab_Coord[1] - 2)
    _GUICtrlTab_SetCurFocus(GUICtrlGetHandle($cTab), $iTab_Index)

EndFunc   ;==>TabEvent

Any use? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Melba you're amazing!! This concept is very very smart!!

However I discovered a bug. If I close the last tab, the last red X doesn't hide itself.

Another thing: It's possible to put the red X in every tabitem (not just only in the active tabitem), detect the clicked X, and simply close the matching tabitem?

Link to comment
Share on other sites

  • Moderators

Floppy,

If I close the last tab, the last red X doesn't hide itself

It should - I added this section of code to do just that:

If $aTab[0] Then
                GUICtrlSetState($cCloseX, $GUI_SHOW)
            Else
                GUICtrlSetState($cCloseX, $GUI_HIDE)
            EndIf

and it does hide it when I test. :)

As to adding a red "X" to each tab - I imagine you could rework the code I posted to do something like that. Perhaps you could try first and see how you get on. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I added just a call of TabEvent() to prevent the bug reported by Floppy.

#include <GuiConstantsEx.au3>
#include <GuiTab.au3>
#include <StaticConstants.au3>
#include <Array.au3>

Global $aTab[5] = [4]

$hGUI = GUICreate("Test", 500, 500)

$cCloseX = GUICtrlCreateLabel("X", 0, 0, 1, 1, BitOR($SS_NOTIFY, $SS_CENTER, $SS_SUNKEN))
GUICtrlSetBkColor($cCloseX, 0xFF8080)

$cTab = GUICtrlCreateTab(5, 5, 390, 260)
$hTab = GUICtrlGetHandle($cTab)
For $i = 1 To $aTab[0]
    $aTab[$i] = GUICtrlCreateTabItem("Tab item - " & $i & " - X")
Next
GUICtrlCreateTabItem("")

TabEvent()

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cTab
            TabEvent()
        Case $cCloseX
            $iIndex = GUICtrlRead($cTab) + 1
            GUICtrlDelete($aTab[$iIndex])
            _ArrayDelete($aTab, $iIndex)
            $aTab[0] -= 1
            If $aTab[0] Then
                GUICtrlSetState($cCloseX, $GUI_SHOW)
            Else
                GUICtrlSetState($cCloseX, $GUI_HIDE)
            EndIf
            TabEvent()
    EndSwitch
WEnd

Func TabEvent()

    Local $iMargin_X = 6, $iMargin_Y = 6
    $iTab_Index = _GUICtrlTab_GetCurSel($hTab)
    $aTab_Coord = _GUICtrlTab_GetItemRect($hTab, $iTab_Index)
    $iOffset = $aTab_Coord[2] - $aTab_Coord[0] - 20
    GUICtrlSetPos($cCloseX, $iMargin_X + $aTab_Coord[0] + $iOffset, $iMargin_Y + $aTab_Coord[1], 20, $aTab_Coord[3] - $aTab_Coord[1] - 2)
    _GUICtrlTab_SetCurFocus(GUICtrlGetHandle($cTab), $iTab_Index)

EndFunc   ;==>TabEvent

When the words fail... music speaks.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...