Jump to content

Recommended Posts

Posted

Ok, Attached is a script that I have been working on and updating for over a year. Now I want to make some updates but one of the things that I am trying to do is not working. I have a GUI with a button that opens a Color pallet window. I want the button to change to the color that has been chosen as well as write the color code to an ini file. It currently writes to the ini but will not update the button color. Any suggestions?

Thanks,

Jon

Line 497 - 507 is where the button is

ControlDaemon.au3

  • Moderators
Posted

JonCross,

Here is one way you could do it: ;)

#include <GUIConstantsEx.au3>
#Include <Misc.au3>

$color = 0xFF0000

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

$Button_C = GUICtrlCreateButton("Attention Color", 200, 80)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button_C
            ; Get a return value from the function
            $iRetColour = _ShowChoice($hGUI, $color, 2, _ChooseColor(2, 0xFF0000, 2, $hGUI),"")
            ; If it is not the Cancel code, then change the color variable
            If $iRetColour <> -1 Then $color = $iRetColour
            ; Change the button backcolour
            GUICtrlSetBkColor($Button_C, $color)
    EndSwitch

WEnd

Func _ShowChoice($hGUI, $color, $Type, $Choose, $sMessage)
    Local $cr
    If $Choose <> -1 Then
            ;IniWriteSection($Server&"\Settings.ini", "Attention", "Key="&$Choose)
    EndIf
    ; Return the value from the _ChooseColor function
    Return $Choose
EndFunc

WARNING: Colouring a button removes all user formatting and sets it to the basic button style. Worse, it makes the button trap the enter key regardless of whether the key has focus. ;) This is a long-standing and well-known bug and will not be fixed any time soon as it is so deeply buried in the basic GUI code. I would strongly recommend NOT changing the colour of the button, but perhaps colouring a label close by or even underneath - something like this: :shocked:

#include <GUIConstantsEx.au3>
#Include <Misc.au3>

$color = 0xFF0000

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

$hLabel = GUICtrlCreateLabel("", 195, 75, 90, 40)
GUICtrlSetState(-1, $GUI_DISABLE)
$Button_C = GUICtrlCreateButton("Attention Color", 200, 80, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button_C
            $iRetColour = _ShowChoice($hGUI, $color, 2, _ChooseColor(2, 0xFF0000, 2, $hGUI),"")
            If $iRetColour <> -1 Then $color = $iRetColour
            GUICtrlSetBkColor($hLabel, $color)
    EndSwitch

WEnd

Func _ShowChoice($hGUI, $color, $Type, $Choose, $sMessage)
    Local $cr
    If $Choose <> -1 Then
            ;IniWriteSection($Server&"\Settings.ini", "Attention", "Key="&$Choose)
    EndIf
    Return $Choose
EndFunc

All clear? :)

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

 

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...