Jump to content

Replace line in Edit


Recommended Posts

  • Moderators

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

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

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

  • Moderators

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

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

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