Jump to content

Recommended Posts

Posted (edited)

Having trouble figuring out something (seemingly) very basic: How to allow a button to be clicked without setting it to have the default control focus (i.e. a black border line around it)?!

Here is a basic GUI with some buttons that do nothing for demonstration. What is needed to allow the user to click a given button and have the GUI appear exactly as when it was opened.. ?

#include <GUIConstants.au3>
$MainGUI = GUICreate("example", 300, 200)
Opt("GUIOnEventMode", 1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetState()

$Button_1 = GUICtrlCreateButton ("Button1",  10, 30, 100)
$Button_2 = GUICtrlCreateButton ("Button2",  10, 60, 100)
$Button_3 = GUICtrlCreateButton ("Button3",  10, 90, 100)

While 1
    Sleep(10)
Wend

Func Close()
    Exit
EndFunc
Edited by Sunaj
Posted

Maybe something like:

#include <GUIConstants.au3>
$MainGUI = GUICreate("example", 300, 200)
Opt("GUIOnEventMode", 1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetState()

$Button_1 = GUICtrlCreateButton ("Button1",  10, 30, 100)
GUICtrlSetOnEvent($Button_1, "Button_Event")
$Button_2 = GUICtrlCreateButton ("Button2",  10, 60, 100)
GUICtrlSetOnEvent($Button_2, "Button_Event")
$Button_3 = GUICtrlCreateButton ("Button3",  10, 90, 100)
GUICtrlSetOnEvent($Button_3, "Button_Event")
$dummy = GUICtrlCreateDummy()

While 1
    Sleep(10)
Wend

Func Close()
    Exit
EndFunc

Func Button_Event()
    GUICtrlSetState($dummy, $GUI_FOCUS)
EndFunc

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Posted (edited)

I reckon its the right kind of approach - it doesn't work though; the first button which is clicked after script is run retains the black edge despite the focus being set to the dummy in your code ;)

Maybe something like:

#include <GUIConstants.au3>
$MainGUI = GUICreate("example", 300, 200)
Opt("GUIOnEventMode", 1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetState()

$Button_1 = GUICtrlCreateButton ("Button1",  10, 30, 100)
GUICtrlSetOnEvent($Button_1, "Button_Event")
$Button_2 = GUICtrlCreateButton ("Button2",  10, 60, 100)
GUICtrlSetOnEvent($Button_2, "Button_Event")
$Button_3 = GUICtrlCreateButton ("Button3",  10, 90, 100)
GUICtrlSetOnEvent($Button_3, "Button_Event")
$dummy = GUICtrlCreateDummy()

While 1
    Sleep(10)
Wend

Func Close()
    Exit
EndFunc

Func Button_Event()
    GUICtrlSetState($dummy, $GUI_FOCUS)
EndFunc
Edited by Sunaj
Posted

I reckon its the right kind of approach - it doesn't work though; the first button which is clicked after script is run retains the black edge despite the focus being set to the dummy in your code ;)

Add alittle style

$BS_DEFPUSHBUTTON

Creates a push button with a heavy black border. If the button is in a dialog box, the user can select the button by pressing the ENTER key, even when the button does not have the input focus. This style is useful for enabling the user to quickly select the most likely option, or default.

#include <GUIConstants.au3>
$MainGUI = GUICreate("example", 300, 200)
Opt("GUIOnEventMode", 1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetState()

$Button_1 = GUICtrlCreateButton ("Button1",  10, 30, 100, Default, $BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent(Default, 'fun')
$Button_2 = GUICtrlCreateButton ("Button2",  10, 60, 100)
$Button_3 = GUICtrlCreateButton ("Button3",  10, 90, 100)

While 1
    Sleep(10)
Wend

Func Close()
    Exit
EndFunc

Func fun()
    MsgBox(0, '', 'ok')
EndFunc
Posted

#include <GUIConstants.au3>
$MainGUI = GUICreate("example", 300, 200)
Opt("GUIOnEventMode", 1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetState()

$Button_1 = GUICtrlCreateButton("Button1", 10, 30, 100)
GUICtrlSetOnEvent($Button_1, "Button1_Event")
$Button_2 = GUICtrlCreateButton("Button2", 10, 60, 100)
GUICtrlSetOnEvent($Button_2, "Button2_Event")
$Button_3 = GUICtrlCreateButton("Button3", 10, 90, 100)
GUICtrlSetOnEvent($Button_3, "Button3_Event")
$dummy = GUICtrlCreateButton("dummny", 10, 120, 100)
GUICtrlSetState($dummy, $GUI_HIDE)

While 1
    Sleep(10)
WEnd

Func Close()
    Exit
EndFunc   ;==>Close

Func Button1_Event()
    GUICtrlSetState($Button_1, $GUI_HIDE)
    GUICtrlSetState($dummy, $GUI_FOCUS)
    GUICtrlSetState($Button_1, $GUI_SHOW)
EndFunc   ;==>Button1_Event

Func Button2_Event()
    GUICtrlSetState($Button_2, $GUI_HIDE)
    GUICtrlSetState($dummy, $GUI_FOCUS)
    GUICtrlSetState($Button_2, $GUI_SHOW)
EndFunc   ;==>Button2_Event

Func Button3_Event()
    GUICtrlSetState($Button_3, $GUI_HIDE)
    GUICtrlSetState($dummy, $GUI_FOCUS)
    GUICtrlSetState($Button_3, $GUI_SHOW)
EndFunc   ;==>Button3_Event

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Posted

Thanks gafrost, you really helped me out on this one! :lmao: , the posted code completely solves the puzzle. The approach is rather esoteric; would never have thought of using GUICtrlSetState in that way myself.. ;)

Best,

Sunaj

#include <GUIConstants.au3>
$MainGUI = GUICreate("example", 300, 200)
Opt("GUIOnEventMode", 1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetState()

$Button_1 = GUICtrlCreateButton("Button1", 10, 30, 100)
GUICtrlSetOnEvent($Button_1, "Button1_Event")
$Button_2 = GUICtrlCreateButton("Button2", 10, 60, 100)
GUICtrlSetOnEvent($Button_2, "Button2_Event")
$Button_3 = GUICtrlCreateButton("Button3", 10, 90, 100)
GUICtrlSetOnEvent($Button_3, "Button3_Event")
$dummy = GUICtrlCreateButton("dummny", 10, 120, 100)
GUICtrlSetState($dummy, $GUI_HIDE)

While 1
    Sleep(10)
WEnd

Func Close()
    Exit
EndFunc   ;==>Close

Func Button1_Event()
    GUICtrlSetState($Button_1, $GUI_HIDE)
    GUICtrlSetState($dummy, $GUI_FOCUS)
    GUICtrlSetState($Button_1, $GUI_SHOW)
EndFunc   ;==>Button1_Event

Func Button2_Event()
    GUICtrlSetState($Button_2, $GUI_HIDE)
    GUICtrlSetState($dummy, $GUI_FOCUS)
    GUICtrlSetState($Button_2, $GUI_SHOW)
EndFunc   ;==>Button2_Event

Func Button3_Event()
    GUICtrlSetState($Button_3, $GUI_HIDE)
    GUICtrlSetState($dummy, $GUI_FOCUS)
    GUICtrlSetState($Button_3, $GUI_SHOW)
EndFunc   ;==>Button3_Event

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