MrChiliCheese Posted January 30, 2013 Share Posted January 30, 2013 Hello there, how to I replace a complete line in a multiline edit? I need to replace the line by the number of the line that is currently selected... Thanks for suggestions Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 30, 2013 Moderators Share Posted January 30, 2013 yetrael, Rather than expecting us write code which may or may not do what you want, why do you not write a small script which shows us exactly what you want. Put some lines into the edit and then tell us which one should be highlighted, which one should be replaced, and what it should be replaced with. Then we know we are all working on the same hymn sheet. 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...
MrChiliCheese Posted January 30, 2013 Author Share Posted January 30, 2013 Func _FormatLine() ;Get line cursor is in $sLine = ControlCommand($mGUI, "", $hEdit, "GetCurrentLine", "") - 1 ;Get count of chars to current line $iCount = 0 For $i = 0 To $sLine $iCount += _GUICtrlEdit_LineLength($hEdit, $i) If $i <> 0 Then $iCount += 2 Next ;Select complete line _GUICtrlEdit_SetSel($hEdit, $iCount - _GUICtrlEdit_LineLength($hEdit, $sLine), $iCount) ;Get current line text and add "###" $sLineText = "### " & _GUICtrlEdit_GetLine($hEdit, $sLine) & " ###" ;Get length of text and create line with "###" $sFormat = StringReplace(StringFormat("%0" & StringLen($sLineText) & "d", "0"), "0", "#") ;Replace current line with Stuff _GUICtrlEdit_ReplaceSel($hEdit, $sFormat & @CRLF & $sLineText & @CRLF & $sFormat & @CRLF) EndFunc ;==>_FormatLine Here we go, that is what i just created... Maybe there is an way to Replace a complete line easier! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 30, 2013 Moderators Share Posted January 30, 2013 yetrael,That seems to work - I like the StringReplace/StringFormat line. I would have done it this way - but that is not to say it is better: Func _FormatLine() $iLine = _GUICtrlEdit_LineFromChar($cEdit, -1) $iCharIndex = _GUICtrlEdit_LineIndex($cEdit, $iLine) $iLength = _GUICtrlEdit_LineLength($cEdit, $iLine) _GUICtrlEdit_SetSel($cEdit, $iCharIndex, $iCharIndex + $iLength) $sLineText = "### " & _GUICtrlEdit_GetLine($cEdit, $iLine) & " ###" $sFormat = StringReplace(StringFormat("%0" & StringLen($sLineText) & "d", "0"), "0", "#") _GUICtrlEdit_ReplaceSel($cEdit, $sFormat & @CRLF & $sLineText & @CRLF & $sFormat) EndFuncM23 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...
MrChiliCheese Posted February 4, 2013 Author Share Posted February 4, 2013 Thanks! Like your version more - right function and not messing around with controlcommand ;-) And it is even faster! 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