Jump to content
Sign in to follow this  
Undutchable

How to select all text in Inputbox

Recommended Posts

Undutchable

Hello,

I hate asking simple questions, but I also prefer to use the simplest code to perform something.

How can I select all text in an Inputbox (GuiCtrlCreateInput)

after I insert the value with GuiCtrlSetData ?

(The intention to select all text is to facilitate insertion of new data, deleting all existing)

I know I have the style $ES_NOHIDESEL which will keep the selection if I change focus,

but how do I select all text in the inputbox in the first place?

Thanks guys. >_<

Share this post


Link to post
Share on other sites
Melba23

Undutchable,

Just use GUICtrlSetData to reset the text - it works as an initial and subsequent text replacement without having to select the existing text:

#include <GUIConstantsEx.au3>

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

$hInput = GUICtrlCreateInput("", 10, 10, 200, 20)
GUICtrlSetData(-1 , "First text")

GUISetState()

Sleep(2000)

GUICtrlSetData($hInput, "Second text")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

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
JSThePatriot

@M23

My assumption is he's not worried about setting the text himself, but if someone tabs into that field for editing, or if they decide they are ready to type after he has given them an example. He wants it to automatically erase his demo text, or the previous set text so they can type immediately.

@Undutchable

I would look at a ControlSend of CTRL+A? I know it's more of a hack, but I couldn't think of anything else off the top of my head.

Thanks,

Jarvis


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites
Melba23

Undutchable,

If JS is correct, then take a look at this code - it removes the initial text as soon as the Input gets focus:

#include <GUIConstantsEx.au3>
#Include <WinAPI.au3>

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

$hInput = GUICtrlCreateInput("", 10, 10, 200, 20)
GUICtrlSetData(-1 , "First text")

GUICtrlCreateButton("Dummy", 10, 50, 80, 30)
GUICtrlSetState(-1, $GUI_FOCUS)

GUISetState()

$fFlag = True

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    If $fFlag And _WinAPI_GetFocus() = ControlGetHandle($hGUI, "", $hInput) Then
        GUICtrlSetData($hInput, "")
        $fFlag = False
    EndIf

WEnd

The button is just there so the initial focus can be somewhere other than the Input. >_<

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
JSThePatriot

@Melba23

Perfect, now either direction he has a solution.

Thanks,

Jarvis


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites
Undutchable

JS was correct. The intention was to remove the text. But I was also trying to avoid sending keystrokes.

I don't know why, it always feels kind of a "hack", like you mentioned.

Melba's example will work for me (replacing dummy button with existing one of course) >_<

Thank you both for the great help.

Cheers :(

Share this post


Link to post
Share on other sites
Yashied

#Include <GUIConstantsEx.au3>
#Include <GUIEdit.au3>
#Include <WindowsConstants.au3>

GUICreate('MyGUI', 400, 90)
$Input1 = GUICtrlCreateInput('My Text 1', 20, 20, 360, 20)
$Input2 = GUICtrlCreateInput('My Text 2', 20, 50, 360, 20)
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    Local $ID = BitAND($wParam, 0xFFFF)

    Switch $ID
        Case $Input1, $Input2 ; etc
            Switch BitShift($wParam, 16)
                Case $EN_SETFOCUS
                    GUICtrlSetState($ID, $GUI_FOCUS)
                    _GUICtrlEdit_SetSel($lParam, 0, -1)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Share this post


Link to post
Share on other sites
Undutchable

Nice..

_GUICtrlEdit_SetSel

There is a function for it after all.

Man, AutoIT grew like crazy. If only the compiled script resulted in size and speed like, for ex, powerbasic or purebasic, and the creator would make millions!

Thanks Yashied. I will use that function alone because I always know the handle of the control.

Congrats to all the community cause you guys are fantastic.

Keep it up >_<

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.