Jump to content

How to select all text in Inputbox


Recommended Posts

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. >_<

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

@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)

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

@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)

Link to comment
Share on other sites

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 :(

Link to comment
Share on other sites

#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

Link to comment
Share on other sites

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 >_<

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...