Search code examples
c#printingline-numbersscintillascintillanet

Print line number when printing the contents from the ScintillaNet


I'm trying to create an IDE using ScintillaNET and I'm using ScintillaNet as by editor, Is there a way to get the line numbers included with the ScintillaNet when I print my text?


Solution

  • The ScintillaNet control has this property:

    public LineCollection Lines { get; }
    

    You can iterate this collection and add the line numbers by this way:

    using System.Windows.Forms;
    using ScintillaNET;
    
    string _s=""; //The string where you will get the results
    foreach (Line _l in scintilla1.Lines) //scintilla1 is the name of your ScintillaNet control
    //Line is a class that represents an individual line of text and has several properties
    {
        _s += "Line " + (_l.Index + 1).ToString() + ": " + _l.Text; 
    }
    MessageBox.Show(_s);
    

    If you set the control with this text:

    Bla, bla, bla 1 
    Bla, bla, bla 2
    Bla, bla, bla 3
    Bla, bla, bla 4
    

    You will get this result:

    enter image description here