Jump to content
Sign in to follow this  
EndFunc

Clear input field on click

Recommended Posts

EndFunc

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.

Share this post


Link to post
Share on other sites
PsaltyDS

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

Share this post


Link to post
Share on other sites
exodius

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
  • Like 1

Share this post


Link to post
Share on other sites
EndFunc

Thanks for the replies, gives me a direction to go.


EndFuncAutoIt is the shiznit. I love it.

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.