Jump to content
r2du-soft

GuiFlatButton_SetColorsEx Unload in another pages

Recommended Posts

Posted (edited)

hi i use from GuiFlatButton but that have a problem.

when i use GuiFlatButton_SetColorsEx  for set button color , if u use GUIDelete() and create another gui and again use from GuiFlatButton_SetColorsEx, then button color not set.

 

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GuiFlatButton.au3>


    Local $aColorsEx_GreenRed = _
    [0x4aa5d2, 0xFFFFFF, 0x4aa5d2, _    ; normal    : Background, Text, Border
     0x4aa5d2, 0xFFFFFF, 0x4aa5d2, _    ; focus     : Background, Text, Border
     0xE43D35, 0xFFFFFF, 0xE43D35, _    ; hover     : Background, Text, Border
     0xFF3D35, 0xFFFFFF, 0xFF3D35]      ; selected  : Background, Text, Border

    Local $aColorsEx_BlueRed = _
    [0x0096a1, 0xFFFFFF, 0x0096a1, _    ; normal    : Background, Text, Border
     0x0096a1, 0xFFFFFF, 0x0096a1, _    ; focus     : Background, Text, Border
     0xE43D35, 0xFFFFFF, 0xE43D35, _    ; hover     : Background, Text, Border
     0xFF3D35, 0xFFFFFF, 0xFF3D35]      ; selected  : Background, Text, Border


Example()

Func Example()

    Local $hGUI, $mybutton1, $mybutton2 , $P2_Shower

    $hGUI = GUICreate("P1", 275, 220)
    GUISetBkColor(0x333333)

    $idLabel = GUICtrlCreateLabel("Click the button", 10, 200, 150, 30)
    GUICtrlSetColor(-1, 0xFFFFFF)


    ;create new button then set the background and foreground colors
    $mybutton1 = GuiFlatButton_Create(" (+) Button 1", 78, 20, 120, 40)
    GuiFlatButton_SetColorsEx(-1, $aColorsEx_GreenRed)

    ;GuiFlatButton_SetBkColor(-1, 0x5555FF)
    ;GuiFlatButton_SetColor(-1, 0xFFFFFF)

    ;create new button then set the background and foreground colors
    $mybutton2 = GuiFlatButton_Create(" (-) Button 2", 78, 80, 120, 40)
    GuiFlatButton_SetColorsEx(-1, $aColorsEx_BlueRed)

    $P2_Shower = GuiFlatButton_Create("Show P2", 78, 140, 120, 40)
    GuiFlatButton_SetColorsEx(-1, $aColorsEx_GreenRed)


    GUISetState(@SW_SHOW, $hGUI)

    Local $i = 0
    Local $iMsg
    While 1
        $iMsg = GUIGetMsg()

        Switch $iMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $mybutton1
                $i += 1
                GUICtrlSetData($idLabel, $i)
                ConsoleWrite($i & @CRLF)
            Case $mybutton2
                $i -= 1
                GUICtrlSetData($idLabel, $i)
                ConsoleWrite($i & @CRLF)
            Case $P2_Shower
            
                GUIDelete()
                Example2()
                ExitLoop

        EndSwitch

        Sleep(10)
    WEnd

EndFunc   ;==>Example


;GUI with one button
Func Example2()


    Local $2_hGUI, $P1_Shower

    $2_hGUI = GUICreate("P2", 275, 220)
    GUISetBkColor(0x333333)

    $idLabel = GUICtrlCreateLabel("Click the button", 10, 200, 150, 30)
    GUICtrlSetColor(-1, 0xFFFFFF)


    ;create new button then set the background and foreground colors
    $P1_Shower = GuiFlatButton_Create("Show P1", 78, 20, 120, 40)
    GuiFlatButton_SetColorsEx(-1, $aColorsEx_BlueRed)


    GUISetState(@SW_SHOW, $2_hGUI)


    Local $2_iMsg
    While 1
        $2_iMsg = GUIGetMsg()

        Switch $2_iMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $P1_Shower
                
                GUIDelete()
                Example()
                ExitLoop
                
        EndSwitch

        Sleep(10)
    WEnd
    
EndFunc   ;==>Example2

 

 i try and dont fix problem and need help.

in under video after GUIDelete() and show P2 and Retrun to the P1 The GuiFlatButton_SetColorsEx not worked

Edited by r2du-soft

Share this post


Link to post
Share on other sites
Posted (edited)

By looking on the sourcecode of the GuiFlatButton udf, i noticed a function which deletes the Buttons created by it.

Then i had the idea that, maybe you should delete the buttons, before using GuiDelete, and, it looks like it fixed the problem:

Insert/replace this into example 1, and the example #2 will show the color button.

Case $P2_Shower
                 GuiFlatButton_Delete($mybutton1)
                GuiFlatButton_Delete($mybutton2)
                GuiFlatButton_Delete($P2_Shower)
                GUIDelete()
                Example2()
                ExitLoop

 

Edited by Dan_555

~Dan~ :Emu.Zone now with Desktop Pets / DeskMates - (Bugfixed UniScrMate 4.1)

Share this post


Link to post
Share on other sites
Posted (edited)

The problem is probably with the Arrays.

If i saw it right, the GuiFlatButton.au3 is using arrays to store the Data of the buttons.

Now, when you create 3 button's, the array is updated to hold 3 buttons.

When GuiDelete is used, the array is not reseted, therefore each new button is added to the last position in the array.

You can test following code, if you change the example2 fuction (from the 1st post) like this:

Func Example2()


    Local $2_hGUI, $P1_Shower

    $2_hGUI = GUICreate("P2", 275, 220)
    GUISetBkColor(0x333333)

    $idLabel = GUICtrlCreateLabel("Click the button", 10, 200, 150, 30)
    GUICtrlSetColor(-1, 0xFFFFFF)


    ;create new button then set the background and foreground colors
    $P1_Shower = GuiFlatButton_Create("Show P1", 78, 10, 120, 40)
    GuiFlatButton_SetColorsEx(-1, $aColorsEx_BlueRed)

    $P2_Shower = GuiFlatButton_Create("Show P2", 78, 50, 120, 40)
    GuiFlatButton_SetColorsEx(-1, $aColorsEx_GreenRed)

    $P3_Shower = GuiFlatButton_Create("Show P3", 78, 90, 120, 40)
    GuiFlatButton_SetColorsEx(-1, $aColorsEx_GreenRed)

    $P4_Shower = GuiFlatButton_Create("Show P4", 78, 130, 120, 40)
    GuiFlatButton_SetColorsEx(-1, $aColorsEx_GreenRed)

    GUISetState(@SW_SHOW, $2_hGUI)

And you will notice that the 4th button does get colored.  (but only in the first function call)

Therefore my assumption is that it has to do with the array's, because GuiDelete does not clear them. 

And so the GuiFlatButton_Delete for each button is needed, for the script, to work properly.

 

 

Edited by Dan_555

~Dan~ :Emu.Zone now with Desktop Pets / DeskMates - (Bugfixed UniScrMate 4.1)

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...