Jump to content

Clear input field on click


EndFunc
 Share

Recommended Posts

Can't seem to figure out how to clear an input field once you click on it to enter a value.

Example if I have "Enter ID" in the input as a default value, I want it to clear the field when you click it to enter the field.

Not as easy as I thought. :)

EndFuncAutoIt is the shiznit. I love it.
Link to comment
Share on other sites

Can't seem to figure out how to clear an input field once you click on it to enter a value.

Example if I have "Enter ID" in the input as a default value, I want it to clear the field when you click it to enter the field.

Not as easy as I thought. :)

You can watch with ControlGetFocus() until your input control comes up. There are also messages you could register, but that might be deeper in the rabbit hole than you want to go.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

How about using a variable to keep track of whether you've cleared it once, then clearing it everytime it gets focused, like this:

#include <GUIConstants.au3>

$Clear = 0

$Form1 = GUICreate("Form1", 242, 99)
$Input1 = GUICtrlCreateInput("Enter ID", 40, 24, 121, 21)
$btn1 = GUICtrlCreateButton ("Catches initial focus", 40, 70)

GUICtrlSetState ($btn1, $GUI_Focus)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch

    If _IsFocused ($Form1, $Input1) And $Clear = 0 Then
        GUICtrlSetData ($Input1, "")
        $Clear = 1
    ElseIf $Clear = 1  And Not _IsFocused ($Form1, $Input1) Then
        $Clear = 0
    EndIf

WEnd


Func _IsFocused($hWnd, $nCID)
    Return ControlGetHandle($hWnd, '', $nCID) = ControlGetHandle($hWnd, '', ControlGetFocus($hWnd))
EndFunc   ;==>_IsFocused
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...