Sign in to follow this  
Followers 0
kylomas

Positioning Controls on Multi-line Tabs

7 posts in this topic

#1 ·  Posted (edited)

Does anyone have any ideas on how to maintain positioning of controls for multi-line tabs?

The following is the best I could come up with but it seems entirely cumbersome.

#include <TabConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <array.au3>
#include <GuiTab.au3>

#AutoIt3Wrapper_Add_Constants=n
local $gui010 = guicreate('',500,500)
local $lbl010 = guictrlcreatelabel('',20,30,200,20,$ss_sunken)
local $inp010 = guictrlcreateinput('',20,60,100,20)
local $btn010 = guictrlcreatebutton('Create Tab',20,450,70,20)
local $btn020 = guictrlcreatebutton('Delete Tab',120,450,70,20)
local $tab010 = guictrlcreatetab(0,0,500,400,$TCS_MULTILINE)
guictrlcreatetabitem('Tab1')
guictrlsetpos($lbl010,_GUICtrlTab_GetDisplayRect(GUICtrlGetHandle($tab010))[0]+20,_GUICtrlTab_GetDisplayRect(GUICtrlGetHandle($tab010))[1]+20)
guictrlsetpos($inp010,_GUICtrlTab_GetDisplayRect(GUICtrlGetHandle($tab010))[0]+20,_GUICtrlTab_GetDisplayRect(GUICtrlGetHandle($tab010))[1]+60)

guisetstate()

local $idx = 1
while 1
    switch guigetmsg()
        case $gui_event_close
            Exit
        case $btn010
            guictrlcreatetabitem('Tab' & $idx + 1)
            guictrlcreatetabitem('')
            $idx += 1
            guictrlsetpos($lbl010,_GUICtrlTab_GetDisplayRect(GUICtrlGetHandle($tab010))[0]+20,_GUICtrlTab_GetDisplayRect(GUICtrlGetHandle($tab010))[1]+20)
            guictrlsetpos($inp010,_GUICtrlTab_GetDisplayRect(GUICtrlGetHandle($tab010))[0]+20,_GUICtrlTab_GetDisplayRect(GUICtrlGetHandle($tab010))[1]+60)
            if _GUICtrlTab_GetDisplayRect(GUICtrlGetHandle($tab010))[3] - _GUICtrlTab_GetDisplayRect(GUICtrlGetHandle($tab010))[1] < 90 then _
                guictrlsetstate($btn010,$gui_disable)
        case $lbl010
            ConsoleWrite('clicked label in tab item ' & guictrlread($tab010) + 1 & @CRLF)
        case $btn020
            guictrldelete(guictrlread($tab010,1))
            if $idx > 0 then $idx -= 1
            guictrlsetpos($lbl010,_GUICtrlTab_GetDisplayRect(GUICtrlGetHandle($tab010))[0]+20,_GUICtrlTab_GetDisplayRect(GUICtrlGetHandle($tab010))[1]+20)
            guictrlsetpos($inp010,_GUICtrlTab_GetDisplayRect(GUICtrlGetHandle($tab010))[0]+20,_GUICtrlTab_GetDisplayRect(GUICtrlGetHandle($tab010))[1]+60)
            if _GUICtrlTab_GetDisplayRect(GUICtrlGetHandle($tab010))[3] - _GUICtrlTab_GetDisplayRect(GUICtrlGetHandle($tab010))[1] > 90 then _
                guictrlsetstate($btn010,$gui_enable)
    EndSwitch
WEnd

I want all of the controls to participate in every tab (sort of like a template).

kylomas

edit: clarity

The controls are created outside of tabitem definitions so that they appears on every tab.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites



Share this post


Link to post
Share on other sites

LarsJ,

Thank you for your response.  Let me explain the problem a little more clearly.  With each row of tabs the tab size decreases requiring the controls to move.  Child windows have exactly the same problem.

The controls are created outside of tabitem definitions so that they appear on every tab.  The problem is keeping the controls lined up relative to each other.  In the code snippet that I posted you can see that I test for a minimum tab size and disable the tab button when that is exceeded.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Yes, but you only have to reposition the child window, not all the controls. When the child window is moved one tab line down, all controls on this child window is also moved one tab line down. And there is no issue about lining up the controls.

Edit: Last sentence.

Edited by LarsJ

Share this post


Link to post
Share on other sites

kylomas,

I see LarsJ and I had the same idea: :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GuiTab.au3>
#include <WinAPI.au3>

Opt("GUIResizeMode", $GUI_DOCKALL)

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

$cButton_1 = GUICtrlCreateButton('Create Tab', 20, 450, 70, 20)
$cButton_2 = GUICtrlCreateButton('Delete Tab', 120, 450, 70, 20)
$cTab = GUICtrlCreateTab(0, 0, 500, 400, $TCS_MULTILINE)
GUICtrlCreateTabItem('Tab_0')
GUICtrlCreateTabItem('')

GUISetState()

$hGUI_Child = GUICreate("", 500, 400, 0, 0, $WS_POPUP, BitOr($WS_EX_MDICHILD, $WS_EX_LAYERED), $hGUI_Main)
GUISetBkColor(0xABCDEF)
_WinAPI_SetLayeredWindowAttributes($hGUI_Child, 0xABCDEF, 250)

$cButton_3 = GUICtrlCreateButton('Test', 20, 30, 200, 20, $ss_sunken)
$cInput = GUICtrlCreateInput('', 20, 60, 100, 20)

GUISetState()

GUISwitch($hGUI_Main)

$iTabY = -1
_CheckTab()

$iCount = 0

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton_3
            ConsoleWrite('clicked button in tab item ' & GUICtrlRead($cTab) & @CRLF)
        Case $cButton_1
            $iCount += 1
            GUICtrlCreateTabItem('Tab_' & $iCount)
            GUICtrlCreateTabItem('')
            _CheckTab()
        Case $cButton_2
            GUICtrlDelete(GUICtrlRead($cTab, 1))
            _CheckTab()
    EndSwitch
WEnd

Func _CheckTab()

    $aTabRect = _GUICtrlTab_GetDisplayRect(GUICtrlGetHandle($cTab))
    If $aTabRect[1] <> $iTabY And $aTabRect[3] - $aTabRect[1] > 100 Then
        $tPoint = DllStructCreate("int X;int Y")
        DllStructSetData($tPoint, "X", $aTabRect[0])
        DllStructSetData($tPoint, "Y", $aTabRect[1])
        _WinAPI_ClientToScreen($hGUI_Main, $tPoint)
        $iX = DllStructGetData($tPoint, "X")
        $iY = DllStructGetData($tPoint, "Y")
        WinMove($hGUI_Child, "", $iX, $iY, $aTabRect[2] - $aTabRect[0], $aTabRect[3] - $aTabRect[1])
        $iTabY = $aTabRect[1]
    EndIf

EndFunc
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

#6 ·  Posted (edited)

Thank you, gentlemen, I see it now...

@LarsJ - If I knew how to include you in the "mark solved" deal I would.  You gave me the answer and I was too thick to see it.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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