Sign in to follow this  
Followers 0
altex

How can I draw two GUI label items and keep one on top of another

8 posts in this topic

Hello,

Just wonder how can I draw two GUI label items (I already know this part  :thumbsup: ). These two labels are not drawn at the same time and they're partly overlapped. My actual question is how to keep the old label box on top of the new one? 

Anyone has idea how to do it? Thanks.

Share this post


Link to post
Share on other sites



Cant you create one label and then update its contet using GUICtrlSetData?

Share this post


Link to post
Share on other sites

Cant you create one label and then update its contet using GUICtrlSetData?

I'm using GUICtrlSetData to adjust the label items. But I need to make sure the most recent  label is underneath the old one. In other words, the old label box should be always on top of new one.

Share this post


Link to post
Share on other sites

altex,

The only way I can think of to do this is to delete and recreate the old label when you update the other - something like this:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

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

$cLabel_1 = GUICtrlCreateLabel("First Label", 10, 10, 200, 200)
GUICtrlSetBkColor($cLabel_1, 0xCCFFCC)

$cLabel_2 = GUICtrlCreateLabel("Second Label", 100, 100, 200, 200, $SS_RIGHT)
GUICtrlSetBkColor($cLabel_2, 0xFFCCCC)

$cBtn_1 = GUICtrlCreateButton("Update Red", 10, 450, 120, 30)
$cBtn_2 = GUICtrlCreateButton("Update Green", 260, 450, 120, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cBtn_1
            GUICtrlSetData($cLabel_2, "Updated label")
            $sData = GUICtrlRead($cLabel_1) ; So you can reset the current content and not the "Old label" text used below
            $aPos = ControlGetPos($hGUI, "", $cLabel_1)
            GUICtrlDelete($cLabel_1)
            $cLabel_1 = GUICtrlCreateLabel("Old label", $aPos[0], $aPos[1], $aPos[2], $aPos[3])
            GUICtrlSetBkColor($cLabel_1, 0xCCFFCC)
        Case $cBtn_2
            GUICtrlSetData($cLabel_1, "Updated label")
            $sData = GUICtrlRead($cLabel_2)
            $aPos = ControlGetPos($hGUI, "", $cLabel_2)
            GUICtrlDelete($cLabel_2)
            $cLabel_2 = GUICtrlCreateLabel("Old label", $aPos[0], $aPos[1], $aPos[2], $aPos[3], $SS_RIGHT)
            GUICtrlSetBkColor($cLabel_2, 0xFFCCCC)
    EndSwitch

WEnd
There must be a more elegant solution - I shall keep looking. :)

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

If using your method and do it quickly, I bet it will make the screen flicker,so not a perfect solution

Share this post


Link to post
Share on other sites

Hi Altex,

        Hope i am not out of the track :) You can create 2 label with same X,Y co-ordinates and hide both of them using 

GUICTRLSETSTATE(-1,$GUI_HIDE)

 

whenever you want to show the label you want to show use the function 

GUICTRLSETSTATE($Lable1,$GUI_SHOW)

Melba please correct me if i am wrong.


Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites

altex,

How about explaining why you want to do this - why must the old label be under the newer one? Then you might get a better suggestion of how you might solve your problem. ;)

Syed23,

Very clever idea - as long as you create the labels in the correct order that works very nicely: :thumbsup:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Global $sLabel = "A"

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

$cLabel_1A = GUICtrlCreateLabel("First Label A", 10, 10, 200, 200)
GUICtrlSetBkColor($cLabel_1A, 0xCCFFCC)

$cLabel_2 = GUICtrlCreateLabel("Second Label", 100, 100, 200, 200, $SS_RIGHT)
GUICtrlSetBkColor($cLabel_2, 0xFFCCCC)

$cLabel_1B = GUICtrlCreateLabel("First Label B", 10, 10, 200, 200)
GUICtrlSetBkColor($cLabel_1B, 0xCCFFCC)
GUICtrlSetState($cLabel_1B, $GUI_HIDE)

$cBtn_1 = GUICtrlCreateButton("Update Red", 10, 450, 120, 30)
$cBtn_2 = GUICtrlCreateButton("Update Green", 260, 450, 120, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cBtn_1
            GUICtrlSetData($cLabel_2, "Updated at " & @SEC)
            If $sLabel = "A" Then
                $sLabel = "B"
                GUICtrlSetState($cLabel_1B, $GUI_SHOW)
                GUICtrlSetState($cLabel_1A, $GUI_HIDE)
            Else
                $sLabel = "A"
                GUICtrlSetState($cLabel_1A, $GUI_SHOW)
                GUICtrlSetState($cLabel_1B, $GUI_HIDE)
            EndIf
        Case $cBtn_2
            GUICtrlSetData($cLabel_1A, "Updated A at " & @SEC)
            GUICtrlSetData($cLabel_1B, "Updated B at " & @SEC)
            If $sLabel = "A" Then
                $sLabel = "B"
                GUICtrlSetState($cLabel_1B, $GUI_SHOW)
                GUICtrlSetState($cLabel_1A, $GUI_HIDE)
            Else
                $sLabel = "A"
                GUICtrlSetState($cLabel_1A, $GUI_SHOW)
                GUICtrlSetState($cLabel_1B, $GUI_HIDE)
            EndIf

    EndSwitch
WEnd
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

Syed23,

Very clever idea - as long as you create the labels in the correct order that works very nicely: :thumbsup:

M23

:guitar: I am feeling very great today.


Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

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