Jump to content
Sign in to follow this  
yoinkster

Clearing an input box when given focus

Recommended Posts

yoinkster

Hey guys,

I'm trying to do something really simple (I hope), my input box has a default string in it that I'd like to clear when the user clicks into it or tabs the cursor into it. I read about GUICtrlSetOnEvent but it says this doesn't work with GUIGetMsg and I'm using that to handle button presses and the like, if at all possible I'd like to not have to rewrite my code!!

So far I've got (stripped) ::

$input = GuiCtrlCreateInput("Enter slice files name...", 5, 5, 130, 20)

Func clearMe()
    GUICtrlSetData($input,"")
EndFunc

All I need is something like GUICtrlInputBoxonfocus($input, "clearMe") but don't know the exactness of how to see when the input box gets the focus. Any ideas?

Cheers :)

Share this post


Link to post
Share on other sites
Melba23

yoinkster,

You need ControlGetFocus. Look at this (it is a bit rough, but you should get the idea):

$hGUI = GUICreate("Test", 500, 500)

$input1 = GuiCtrlCreateInput("Filled", 5, 5, 130, 20)
$input2 = GuiCtrlCreateInput("Filled", 5, 55, 130, 20)

GUISetState()


While 1

    If GUIGetMsg() = -3 Then Exit
    
    Switch ControlGetFocus($hGUI, "")
        Case "Edit1"
            clearMe($input1, $input2)
        Case "Edit2"
            clearMe($input2, $input1)
    EndSwitch

WEnd

Func clearMe($ctrl1, $ctrl2)
    GUICtrlSetData($ctrl1,"")
    GUICtrlSetData($ctrl2,"Filled again!")
EndFunc

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

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

 

Share this post


Link to post
Share on other sites
yoinkster

hmm ok, I sort of get that.

Don't understand how/why Edit1 and Edit2 works but whatever.

When I did that though, I couldn't type in the box, it just kept on clearing it, I'm guessing, as it still had the focus.

$gui = GUICreate("All Aboard The FAIL Lose", 462, 190 + $Correction)
$input = GuiCtrlCreateInput("Enter slice files name...", 5, 5, 130, 20)
GUISetState()

While 1
    Switch ControlGetFocus($gui, "")
        Case "Edit1"
            clearMe()
    EndSwitch
WEnd

Func clearMe()
    GUICtrlSetData($input,"")
EndFuncoÝ÷ Ú+0«HßÛÞDv+Hq©º"¶¥ÛeyÈ^jÖ§uØjëh×6Func clearMe()
    If GUICtrlRead($input) = "Enter slice files name..." Then
        GUICtrlSetData($input,"")
    EndIf
EndFunc

is that a good idea or will that become a memory hog or something if it's constantly running the clearMe function when you are typing in the input box ??

EndOfEdit*

Edited by yoinkster

Share this post


Link to post
Share on other sites
Melba23

yoinkster,

That was "proof of concept" code - not an answer to your specific problem.

If you read the Help file for ControlGetFocus (always a good idea with a new function!) you will see that it returns the ClassNameNN of the control. Hence the use of "Edit1" and "Edit2" rather than the more normal controlID.

If you only want the function to run the first time the edit has focus, I would suggest setting a flag in the function on the first pass - then testing for it on subsequent calls and returning immediately when it is found to be set.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

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

 

Share this post


Link to post
Share on other sites
yoinkster

Yeah I read it and got a bit confused to begin with but I get it now, using the info tool helps explain a lot.

I've shoved a bool in there to control calls to the function anyhoo. Thanks a lot for your help bud :)

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.