Champak Posted September 12, 2022 Share Posted September 12, 2022 Just spent 2 hrs tracking this down...beyond pissed because it doesn't make sense to me. I have a function that is activated with a button and then sets the color of the button with GUICtrlSetBkColor at the end of the function. The problem is anytime I press the enter key after I have pressed the button, the enter key activates that previous function that was activated with the button. Like the button now has focus so the enter key activates it now. Even if I try to set the focus on something else after the setbkcolor, the function still activates until I remove the setbkcolor. GUISetState(@SW_LOCK, $hGUI) If $fHSCategories = 1 Then $fHSCategories = 0 _GUICtrlListView_SetColumnWidth($cLV_1, $Col_Cat3Parent, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_SetColumnWidth($cLV_1, $Col_Cat3Level1, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_SetColumnWidth($cLV_1, $Col_Cat3Level2, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_SetColumnWidth($cLV_1, $Col_CatUnisex, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_SetColumnWidth($cLV_1, $Col_Cat1Parent, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_SetColumnWidth($cLV_1, $Col_Cat1Level1, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_SetColumnWidth($cLV_1, $Col_Cat1Level2, $LVSCW_AUTOSIZE_USEHEADER) GUICtrlSetBkColor($sHSCategories, 0xF0F0F0) ElseIf $fHSCategories = 0 Then $fHSCategories = 1 _GUICtrlListView_SetColumnWidth($cLV_1, $Col_Cat3Parent, 0) _GUICtrlListView_SetColumnWidth($cLV_1, $Col_Cat3Level1, 0) _GUICtrlListView_SetColumnWidth($cLV_1, $Col_Cat3Level2, 0) _GUICtrlListView_SetColumnWidth($cLV_1, $Col_CatUnisex, 0) _GUICtrlListView_SetColumnWidth($cLV_1, $Col_Cat1Parent, 0) _GUICtrlListView_SetColumnWidth($cLV_1, $Col_Cat1Level1, 0) _GUICtrlListView_SetColumnWidth($cLV_1, $Col_Cat1Level2, 0) GUICtrlSetBkColor($sHSCategories, 0x00FF00) EndIf GUISetState(@SW_UNLOCK, $hGUI) How can I fix this? Link to comment Share on other sites More sharing options...
argumentum Posted September 12, 2022 Share Posted September 12, 2022 (edited) 7 hours ago, Champak said: The problem is anytime I press the enter key after I have pressed the button, the enter key activates that previous function ... .. that's not there. Post a running example. Edited September 12, 2022 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 12, 2022 Moderators Share Posted September 12, 2022 Champak, Setting button colours screws up something deep inside AutoIt which previous developers have said is too difficult to fix and results in the button acting strangely. Search the forum for the many earlier posts from me about this. Solution: do not colour buttons! 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 Link to comment Share on other sites More sharing options...
argumentum Posted September 12, 2022 Share Posted September 12, 2022 3 hours ago, Melba23 said: Setting button colours screws up something deep inside AutoIt hmm, use a label or a pic. ? taurus905 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
kurtykurtyboy Posted September 12, 2022 Share Posted September 12, 2022 (edited) It seems to me the problem is not related to background color at all. If you click a button, it will then have focus so the Enter button will activate the button. Am I not understanding the problem? If that is the case, you could make a "hidden" button off the screen to accept focus after you click the button. Would something like this work? expandcollapse popup#include <GUIConstantsEx.au3> Global $hGUI = GUICreate("MyGUI", 400, 350, 760, 365) Global $Button_1 = GUICtrlCreateButton("idle", 30, 40, 125, 41) Global $Button_2 = GUICtrlCreateButton("idle", 30, 100, 125, 41) ;create a hidden button to steal focus form other buttons Global $Button_hidden = GUICtrlCreateButton("", -1, -1, 0, 0) _main() Func _main() GUISetState(@SW_SHOWNORMAL) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button_1 GUICtrlSetData($Button_1, "clicked") GUICtrlSetData($Button_2, "idle") ConsoleWrite("button 1" & @CRLF) GUICtrlSetBkColor($Button_1, 0xF0F0F0) GUICtrlSetState($Button_hidden, $GUI_FOCUS) Case $Button_2 GUICtrlSetData($Button_1, "idle") GUICtrlSetData($Button_2, "clicked") ConsoleWrite("button 2" & @CRLF) GUICtrlSetBkColor($Button_1, 0x00FF00) GUICtrlSetState($Button_hidden, $GUI_FOCUS) Case $Button_hidden ;do nothing Case Else EndSwitch WEnd EndFunc ;==>_main For coloring GUI buttons, here is my take on easily setting background/foreground colors of buttons, that doesn't sacrifice functionality or appearance. Edited September 12, 2022 by kurtykurtyboy Link to comment Share on other sites More sharing options...
Champak Posted September 13, 2022 Author Share Posted September 13, 2022 No I tried that, it makes sense that it should work, but it doesn't. I set the focus to an input, you would see the curser activate in the input, but once the enter key is hit (the enter key is mapped to do something specific in my app) the button is activated again. What's bothersome is that it is a known issue and a decision was made not to correct it with no notice in the help file about it..."will cause unpredictable issues with buttons.", but there is other notes on button coloring. Oh well, on to using images. Thanks M23. Link to comment Share on other sites More sharing options...
kurtykurtyboy Posted September 13, 2022 Share Posted September 13, 2022 Oh I see it now. The issue wasn't there in my example above - it only appears after adding an input control and hitting enter inside the input. Very strange. Anyway, a quick test with the GuiFlatButton UDF linked above worked just fine. No weird behavior like with the standard buttons. That is, if you're OK with rectangular buttons. Link to comment Share on other sites More sharing options...
Champak Posted September 19, 2022 Author Share Posted September 19, 2022 Thanks, I'll look into the UDF. Link to comment Share on other sites More sharing options...
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