Jump to content

How to set focus on 2 controls


notta
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

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

 

Link to comment
Share on other sites

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...