JonCross Posted October 13, 2010 Posted October 13, 2010 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 isControlDaemon.au3
Moderators Melba23 Posted October 14, 2010 Moderators Posted October 14, 2010 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 EndFuncWARNING: 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: #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 EndFuncAll clear? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now