ScriptCrafter Posted November 28, 2010 Share Posted November 28, 2010 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 28, 2010 Moderators Share Posted November 28, 2010 ScriptCrafter, That was fun! Does this meet your requirements? #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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
ScriptCrafter Posted November 28, 2010 Author Share Posted November 28, 2010 My hero <3 Thanks Mate -SC Link to comment Share on other sites More sharing options...
ScriptCrafter Posted November 28, 2010 Author Share Posted November 28, 2010 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 29, 2010 Moderators Share Posted November 29, 2010 SriptCrafter. How about this? expandcollapse popup#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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
UEZ Posted November 29, 2010 Share Posted November 29, 2010 @Melba: it is not working properly 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 29, 2010 Moderators Share Posted November 29, 2010 (edited) UEZ, Working on it! M23 Edit: Try this one: expandcollapse popup#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 November 29, 2010 by Melba23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
UEZ Posted November 29, 2010 Share Posted November 29, 2010 (edited) @M23: seems to be working now 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 EndFuncBr,UEZEdit: forgot one check Edited November 29, 2010 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 29, 2010 Moderators Share Posted November 29, 2010 (edited) UEZ, Nice work. Subtly different in behaviour - but a lot shorter! M23 Edit: I see it just got a bit longer. Not as easy as it first seems, is it? Edited November 29, 2010 by Melba23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
ZacUSNYR Posted November 29, 2010 Share Posted November 29, 2010 Always love a challenge, but i'd just have used a label :lol Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now