Jump to content

[Solved] Button Selection after Pressing it

Recommended Posts

Hello, all, i have met 1 small problem, AGAIN.

So here is my problem... I just want to make a button which image would change abit after pressing it. All was OK, but later i had noticed, that after i press any button once it becomes "selected" (you may see special borders) and if i want to press other button and see same "selection" efect (you cant see special borders), i need to press other buttom 2 times to remove "selection" efect from previous button and use it on 2nd.

With 1st button you just change image in button and 2nd one is just a test button, to see what i am talking about.

Here is my code, it may be easyer to understand what did i mean:

#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>

Opt("GUIOnEventMode", 1)

$RedLight = @ScriptDir & "\Image\RedLight.bmp"
$GreenLight = @ScriptDir & "\Image\GreenLight.bmp"
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$Button = GUICtrlCreateButton("1", 87, 42, 83, 25)
$ButtonList = _GUIImageList_Create(18, 18, 5, 3)
_GUIImageList_AddBitmap($ButtonList, $RedLight)
_GUICtrlButton_SetImageList($Button, $ButtonList,0,4,1,1,2) 
GUICtrlSetOnEvent($Button, "_Button1")
$Button2 = GUICtrlCreateButton("2", 175, 42, 83, 25)
$ButtonList2 = _GUIImageList_Create(18, 18, 5, 3)
_GUIImageList_AddBitmap($ButtonList2, $RedLight)
_GUICtrlButton_SetImageList($Button2, $ButtonList2,0,4,1,1,2) 
GUICtrlSetOnEvent($Button2, "_Button2")
$data = GuiCtrlCreateInput("sss",10,10)

While 1

Func _Button1()
$ButtonList = _GUIImageList_Create(18, 18, 5, 3)
_GUIImageList_AddBitmap($ButtonList, $GreenLight)
_GUICtrlButton_SetImageList($Button, $ButtonList,0,4,1,1,2) 
GuiCtrlSetData($data, "aaaaa")
Func _Exit()
Edited by Makaule
Link to comment
Share on other sites

  • Moderators


If I understand you correctly, I believe your problem will be solved by moving the focus away from the button once you have pressed it. You need to add a line to your _Button1 function like this:

GUICtrlSetData($data, "aaaaa")
ControlFocus("Test", "", $data)

Does that work for you? It certainly changes the behaviour of the buttons for me. :(


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:


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


Link to comment
Share on other sites

Thanks, i were looking for something like that, but problem was that i were trying to find it in Buttom Options :(

Thanks, Melba, Problem solved.

By The way, its also possible to solve my problem using _GUICtrlButton_SetFocus

Edited by Makaule
Link to comment
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...