Hi

A few days ago I started developing a little HTML Editor.
I tryed integrating line numbers into it but im not realy lucky right now.

I use the KeyDown event to respond on the Return/Backspace keys then I count the lines and write it into a second RT-box left to the main Editor RT-box but there are some problems with this solution.
Sometimes there are too much or not enough numbers... then I cant find an event for automatic line breaks.
How would you solve this?

my solution:
C#
private void richTextBox1_KeyDown(object sender, KeyEventArgs e)

        {

            if (e.KeyCode == Keys.Enter)

            {

                generateTextLineContext(richTextBox1.Lines.Length);

            }

 

            if (e.KeyCode == Keys.Back)

            {

                generateTextLineContext(richTextBox1.Lines.Length);

            }

        }

 

        private void generateTextLineContext(int lineNumber)

        {

            richTextBox2.ResetText();

            for (int i = 1; i <= lineNumber; i++)

            {

                richTextBox2.Text += i.ToString() + System.Environment.NewLine;

            }  

        }

Thanks!