Sign in to follow this  
Followers 0
ScriptCrafter

Input Read Only Text

10 posts in this topic

I would like some part of my text to be read only in an input box.

Here is what I have so far, but it doesnt appear to work.

$Input1 = GUICtrlCreateInput("", 15, 315, 620, 20)
$LINE = _GUICtrlEdit_GetLineCount($Edit1)
$TXT = _GUICtrlEdit_GetLine($Edit1, ($LINE - 1))
GUICtrlSetData($Input1, _GUICtrlEdit_SetReadOnly($TXT, True))

Is it possible to keep some string (text) in an input field as read only, and allow the user to type anything after it?

Thanks

-SC

Share this post


Link to post
Share on other sites



ScriptCrafter,

That was fun! :(

Does this meet your requirements? :graduated:

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#Include <GuiEdit.au3>

$sFixedText = "This text is fixed"
$iFixedLen = StringLen($sFixedText)

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

$hInput = GUICtrlCreateInput ($sFixedText, 10, 10, 300, 20)
$hInput_Handle = GUICtrlGetHandle(-1)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; Check user is not trying to backspace over any of the fixed text
    If _GUICtrlEdit_GetModify($hInput_Handle) Then
        If StringLen(GUICtrlRead($hInput)) < $iFixedLen Then
            GUICtrlSetData($hInput, $sFixedText)
        EndIf
    EndIf

    ; Check user is not trying to put the cursor into the fixed text
    $aCurSel = _GUICtrlEdit_GetSel($hInput_Handle)
    If $aCurSel[0] < $iFixedLen Then
        _GUICtrlEdit_SetSel($hInput_Handle, $iFixedLen, $iFixedLen)
    EndIf

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

My hero <3

Thanks Mate

-SC

Share this post


Link to post
Share on other sites

Is it possible to make it so the cursor is allowed to be moved but no new text or ENTER key enabled while moved?

-SC

Share this post


Link to post
Share on other sites

SriptCrafter.

How about this? :graduated:

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#Include <GuiEdit.au3>

$sFixedText = "This text is fixed"
$iFixedLen = StringLen($sFixedText)

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

$hInput = GUICtrlCreateInput ($sFixedText, 10, 10, 300, 20)
$hInput_Handle = GUICtrlGetHandle(-1)

GUISetState()

; Store current text and length
$sLastText = $sFixedText
$iLastLen = $iFixedLen

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; Get current text
    $sCurrText = GUICtrlRead($hInput)
    ; Get current cursor position
    $aCurSel = _GUICtrlEdit_GetSel($hInput_Handle)
    ; Check cursor position
    If $aCurSel[1] >= $iFixedLen Then
        ; Cursor beyond fixed text, so allow changes and keep a copy
        $sLastText = $sCurrText
        $iLastLen = StringLen($sLastText)
    ElseIf $aCurSel[1] <> $iLastLen Then
        ; If cursor in the fixed text then reset last good text if any changes made
        If $sCurrText <> $sLastText Then GUICtrlSetData($hInput, $sLastText)
        ; And keep cursor at the required position
        _GUICtrlEdit_SetSel($hInput_Handle, $aCurSel[0], $aCurSel[0])
    EndIf

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

@Melba: it is not working properly Posted Image

E.g. if you press any key and hold it pressed, cursor will move to the right but it will start writing the key starting from e in word fixed!

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

UEZ,

:graduated:

Working on it! :(

M23

Edit:

Try this one: :D

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#Include <GuiEdit.au3>

$sFixedText = "This text is fixed"
$iFixedLen = StringLen($sFixedText)

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

$hInput = GUICtrlCreateInput ($sFixedText, 10, 10, 300, 20)
$hInput_Handle = GUICtrlGetHandle(-1)

GUISetState()

; Store current text and length
$sLastText = $sFixedText
$iLastLen = $iFixedLen
$iLastPos = $iFixedLen

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch


    ; Get current cursor position
    $aCurSel = _GUICtrlEdit_GetSel($hInput_Handle)
    ; Check if cursor has moved
    If $aCurSel[1] <> $iLastPos Then
        ; Get current text
        $sCurrText = GUICtrlRead($hInput)
        If $aCurSel[1] > $iFixedLen Then
            ; Cursor beyond fixed text, so allow changes and keep a copy
            $sLastText = $sCurrText
            $iLastLen = StringLen($sLastText)
            $iLastPos = $aCurSel[1]
        ElseIf $aCurSel[1] = $iFixedLen Then
            If $iLastPos > $iFixedLen Then
                ; Cursor returning back to fixed text, so allow changes and keep a copy
                $sLastText = $sCurrText
                $iLastLen = StringLen($sLastText)
                $iLastPos = $aCurSel[1]
            Else
                ; Cursor moving out to end of fixed text
                GUICtrlSetData($hInput, $sLastText)
                ; And keep cursor at the required position
                _GUICtrlEdit_SetSel($hInput_Handle, $aCurSel[0], $aCurSel[0])
                $iLastPos = $aCurSel[1]
            EndIf
        Else
            ; Cursor is within fixed text
            GUICtrlSetData($hInput, $sLastText)
            ; And keep cursor at the required position
            _GUICtrlEdit_SetSel($hInput_Handle, $aCurSel[0], $aCurSel[0])
            $iLastPos = $aCurSel[1]
        EndIf
    EndIf

WEnd
Edited by Melba23

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

#8 ·  Posted (edited)

@M23: seems to be working now Posted Image

Here my version:

#include <GUIConstantsEx.au3>

$sFixedText = "This text is fixed:"
$sFixedText_l = StringLen($sFixedText)

$hGUI = GUICreate("Test", 500, 500)
$hInput = GUICtrlCreateInput ($sFixedText, 10, 10, 300, 20)
GUISetState()

GUIRegisterMsg(0x0111, '_WM_COMMAND')

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $chk = BitAND($wParam, 0x0000FFFF), $i
    Switch $chk
        Case $hInput
            If StringLeft(GUICtrlRead($hInput), $sFixedText_l) == $sFixedText Then
                $i = StringMid(GUICtrlRead($hInput), $sFixedText_l + 1)
                GUICtrlSetData($hInput, $sFixedText & $i)
            Else
                GUICtrlSetData($hInput, $sFixedText & StringMid(GUICtrlRead($hInput), $sFixedText_l + 2))
            EndIf
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Br,

UEZ

Edit: forgot one check Posted Image

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

UEZ,

Nice work. :graduated:

Subtly different in behaviour - but a lot shorter! :D

M23

Edit: I see it just got a bit longer. :( Not as easy as it first seems, is it? :D

Edited by Melba23

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

Always love a challenge, but i'd just have used a label :lol

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  
Followers 0