Jump to content

Problem with input box


Jdub
 Share

Recommended Posts

A stupid issue this I expect. When I run this script how do I get the cursor to return to the input box after the calculate button or clear button is pressed? When I run this the focus seems elsewhere and even clicking in the input box only works if you click at a particular point. What am I doing wrong?

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode 
$mainwindow = GUICreate("Window1", 310, 295)

$displaytext1 = ("")
GUICtrlSetFont (-1,11)
$monthly = GUICtrlCreateInput("",110,40,90,30, $ES_RIGHT)
GUICtrlSetFont (-1,14)
$CalcButton  = GUICtrlCreateButton("Calculate", 10, 80, 80, 20, $BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent($CalcButton, "CalcButton")
$ExitButton = GUICtrlCreateButton("Exit", 190, 80, 80, 20)
GUICtrlSetOnEvent($ExitButton, "ExitButton")
$ClearButton = GUICtrlCreateButton("Clear", 100, 80, 80, 20)
GUICtrlSetOnEvent($ClearButton, "ClearButton")
GuiCtrlCreateTab(5, 125, 300, 160)

GUISetState(@SW_SHOW)


While 1
  Sleep(1000)  ; Idle around
WEnd


Func CalcButton()
    $msg = GUIGetMsg()
    $text = GUICtrlRead($monthly)
    $displaytext1 = ("£" & $text & " entered... ")

    $result1 = GUICtrlCreateLabel($displaytext1, 10, 130, 280)
    GUICtrlSetFont (-1,10)
    GUICtrlSetColor(-1,0x2e8b57)    ; Sea Green
    GUICtrlSetBkColor(-1,0xFFFFFF)

    GUISetState(@SW_SHOW)

EndFunc

Func CLOSEClicked()
  Exit
EndFunc

Func ClearButton()
    $msg = GUIGetMsg()
    $text = ""
    $displaytext1 = ""

    $result1 = GUICtrlCreateLabel($displaytext1, 10, 130, 280)
    GUICtrlSetFont (-1,10)
    GUICtrlSetColor(-1,0x2e8b57)    ; Sea Green
    GUICtrlSetBkColor(-1,0xFFFFFF)

    GUISetState(@SW_SHOW)

EndFunc

Func ExitButton()
  Exit
EndFunc
Link to comment
Share on other sites

At the end of your CalcButton and ClearButton functions, add "GUICtrlSetState($monthly, $GUI_FOCUS)".

Also, just before that, in ClearButton, you may want to add "GUICtrlSetData($monthly, "")". That will clear the control.

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