Sign in to follow this  
Followers 0
Floppy

TabItems with close button

10 posts in this topic

Hi,

is it possible to create TabItems with close button? (like firefox/chrome tabs)

I need them because I'm creating a web browser

Share this post


Link to post
Share on other sites



Floppy,

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

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Melba, how do I put the close button in every tab?

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Maybe I don't made myself clear.

I want a Close button inside each tabitem header (like that red X in Firefox or Chrome tabs).

Is possible to do that thing?

Share this post


Link to post
Share on other sites
Is possible?

Share this post


Link to post
Share on other sites

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

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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

Share this post


Link to post
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
Sign in to follow this  
Followers 0