Jump to content

How to create line numbers for edit and inputs


Recommended Posts

Here is a start. I'm sure there are probably better ways to do it, but since you haven't received a response, I thought I'd give you something to work off of.

#include <GUIConstants.au3>
#include <GuiEdit.au3>
#include <Misc.au3>

$form = GUICreate("Line Numbers on Edit", 633, 447, 193, 115)
$edit = GUICtrlCreateEdit("", 8, 8, 617, 433)
GUICtrlSetData(-1, "|1|  Some text on line 1"&@CRLF&"|2|  The second line of text"&@CRLF&"|3|  Some more"&@CRLF&"|4|  and more")
GUISetState(@SW_SHOW)
$button = GUICtrlCreateButton ("add nums",0,0,50,50)
GUICtrlSetState($button,$GUI_HIDE)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    
    If _IsPressed ("0D") Then
            addNums()
            While _IsPressed ("0D")
                Sleep(20) ; Avoid excessive number of calls to addNums
            WEnd
            addNums()
    EndIf
    
WEnd

Func addNums()
    $text = GUICtrlRead($edit)
    $arr = StringSplit($text,@CRLF,1)
    $finaltext = ""
    For $i = 1 To $arr[0]
        $linetext = $arr[$i]
        If StringRegExp($linetext,"\A\|(([0-9]{1,5})\|)",1)=1 Then
            $finaltext = $finaltext & @CRLF & "|"&$i&"|  "&$linetext
        Else
            $finaltext = $finaltext & @CRLF & $linetext
        EndIf
    Next
    GUICtrlSetData($edit,StringRight ($finaltext,StringLen($finaltext)-2))
EndFunc
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...