yoinkster Posted February 10, 2009 Share Posted February 10, 2009 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 10, 2009 Moderators Share Posted February 10, 2009 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!") EndFuncM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
yoinkster Posted February 10, 2009 Author Share Posted February 10, 2009 (edited) 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 February 10, 2009 by yoinkster Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 10, 2009 Moderators Share Posted February 10, 2009 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
yoinkster Posted February 10, 2009 Author Share Posted February 10, 2009 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now