Jump to content
Sign in to follow this  
notta

How to set focus on 2 controls

Recommended Posts

notta

I created a custom gui with the an input box and a yes no button. By default the cursor is blinking in the inputbox like I want, but I also want the button defaulted to "yes" so the user only has to hit enter instead of moving the mouse to click ok. How can you set the focus on 2 items? $GUI_DEFBUTTON didn't help me out. Thanks.

Share this post


Link to post
Share on other sites
Nahuel

Well... it's not $GUI_DEFBUTTON, it's $BS_DEFPUSHBUTTON

Try this

#include <GUIConstants.au3>

GUICreate("", 292, 174, 211, 167)
$Input1 = GUICtrlCreateInput("Write something here and press enter", 34, 40, 201, 21)
$Button1 = GUICtrlCreateButton("Ok", 54, 102, 165, 35, $BS_DEFPUSHBUTTON)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            MsgBox(0,"","Hey it works! "&GUICtrlRead($Input1))
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites
wolf9228

Well... it's not $GUI_DEFBUTTON, it's $BS_DEFPUSHBUTTON

Try this

#include <GUIConstants.au3>

GUICreate("", 292, 174, 211, 167)
$Input1 = GUICtrlCreateInput("Write something here and press enter", 34, 40, 201, 21)
$Button1 = GUICtrlCreateButton("Ok", 54, 102, 165, 35, $BS_DEFPUSHBUTTON)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            MsgBox(0,"","Hey it works! "&GUICtrlRead($Input1))
    EndSwitch
WEnd
or

#include <GUIConstants.au3>

$g =GUICreate("GUICreate", 292, 174, 211, 167)
$Input1 = GUICtrlCreateInput("Write something here and press enter", 34, 40, 201, 21)
$Button1 = GUICtrlCreateButton("Ok", 54, 102, 165, 35)
GUISetState(@SW_SHOW)
GUICtrlSetState ($Button1, $GUI_FOCUS )

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
           MsgBox(0,"","Hey it works! "&GUICtrlRead($Input1))
    EndSwitch
WEnd

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites
Nahuel

or

#include <GUIConstants.au3>

$g =GUICreate("GUICreate", 292, 174, 211, 167)
$Input1 = GUICtrlCreateInput("Write something here and press enter", 34, 40, 201, 21)
$Button1 = GUICtrlCreateButton("Ok", 54, 102, 165, 35)
GUISetState(@SW_SHOW)
GUICtrlSetState ($Button1, $GUI_FOCUS )

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
           MsgBox(0,"","Hey it works! "&GUICtrlRead($Input1))
    EndSwitch
WEnd
No no, you see, the button gains focus at first run and it works if you press enter. But you have to click in the input box to be able to type and then the button loses focus....

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.