Jump to content

selecting all text in a control on click


iamtheky
 Share

Go to solution Solved by jdelaney,

Recommended Posts

guictrlcreateinput, take the example for example.  Write some text in the first parameter.  How would you go about selecting all the text (instead of just setting the cursor) when a user left clicks amongst the controls, the behavior that exists when they are tabbed between.  This has to have been asked before and my search just sucking tonight.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

probably other ways, as well:

#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
Example()

Func Example()
    Local $file, $btn, $msg

    $g = GUICreate(" My GUI input acceptfile", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES
    $file = GUICtrlCreateInput("", 10, 5, 300, 20)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
    $i = GUICtrlCreateInput("", 10, 35, 300, 20) ; will not accept drag&drop files
    $btn = GUICtrlCreateButton("Ok", 40, 75, 60, 20)

    GUISetState()

    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        Select
            Case $msg = $btn
                ConsoleWrite( GUICtrlRead($i) & @CRLF)
                ControlFocus($g, "", $i)
                _GUICtrlEdit_SetSel($i, 0, StringLen(GUICtrlRead($i)))

        EndSelect
    WEnd

    MsgBox(4096, "drag drop file", GUICtrlRead($file))
EndFunc   ;==>Example

click the button to perform _guictrledit_setsel...use the second input.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

set

$file = GUICtrlCreateInput("test", 10, 5, 300, 20)

$i = GUICtrlCreateInput("test", 10, 35, 300, 20)

and tab between them and the text is selected.

and left click in them, and i get a cursor at the end.  I want left click to mimic the tab behavior, I dont understand how to do that from your example....yet, im still trying.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

  • Solution

how about this:

#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
Example()

Func Example()
    Local $file, $btn, $msg, $focus="", $last = ""

    $g = GUICreate(" My GUI input acceptfile", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES
    $i1 = GUICtrlCreateInput("", 10, 5, 300, 20)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
    $i2 = GUICtrlCreateInput("", 10, 35, 300, 20) ; will not accept drag&drop files
    $btn = GUICtrlCreateButton("Ok", 40, 75, 60, 20)

    GUISetState()

    $s1 = "Edit1"
    $s2 = "Edit2"
    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        $focus = String(ControlGetFocus($g))
        Switch $focus
            Case $s1
                If $focus <> $last Then
                    $last = $focus
                    ControlFocus($g, "", $i1)
                    ConsoleWrite( GUICtrlRead($i1) & @CRLF)
                    _GUICtrlEdit_SetSel($i1, 0, StringLen(GUICtrlRead($i1)))
                EndIf
            Case $s2
                If $focus <> $last Then
                    $last = $focus
                    ControlFocus($g, "", $i2)
                    ConsoleWrite( GUICtrlRead($i2) & @CRLF)
                    _GUICtrlEdit_SetSel($i2, 0, StringLen(GUICtrlRead($i2)))
                EndIf
        EndSwitch

        Select
            Case $msg = $btn
                ConsoleWrite( GUICtrlRead($i2) & @CRLF)
                ControlFocus($g, "", $i2)
                _GUICtrlEdit_SetSel($i2, 0, StringLen(GUICtrlRead($i2)))

        EndSelect
    WEnd

EndFunc   ;==>Example

Simplified:

#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
Example()

Func Example()
    Local $file, $btn, $msg, $focus="", $last = ""

    $g = GUICreate(" My GUI input acceptfile", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES
    $i1 = GUICtrlCreateInput("", 10, 5, 300, 20)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
    $i2 = GUICtrlCreateInput("", 10, 35, 300, 20) ; will not accept drag&drop files
    $btn = GUICtrlCreateButton("Ok", 40, 75, 60, 20)

    GUISetState()

    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        $focus = String(ControlGetFocus($g))
        If StringInStr($focus,"Edit") And $focus <> $last Then
            $last = $focus
            $h = ControlGetHandle($g, "",$focus)
            
            _GUICtrlEdit_SetSel($h, 0, StringLen(ControlGetText($g,"",$h)))
        EndIf
    WEnd
EndFunc   ;==>Example
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Both seem to work fine.  Thank you sir.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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