An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll

Posted by Tanner on Stack Overflow See other posts from Stack Overflow or by Tanner
Published on 2010-05-11T17:19:59Z Indexed on 2010/05/11 17:24 UTC
Read the original article Hit count: 369

OK, Im trying to highlight keywords in a richtextbox, the problem is I've got the code to highlight only the visible text on textChanged event,so I tryed putting the code in the richtextbox VScroll, so when I scrolled up it would highlight the text that wasn't visible before, but every time I start to scroll I get this error: "An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll" Does any one know why? Or maybe a way I could highlight the words while scrolling? Thanks, Tanner.

        int selectionstart = richTextBox1.Selectionstart;
        int topIndex = richTextBox1.GetCharIndexFromPosition(new Point(1, 1));//This is where I get the error.
        int bottomIndex = richTextBox1.GetCharIndexFromPosition(new Point(1, richTextBox1.Height - 1));

        int topLine = richTextBox1.GetLineFromCharIndex(topIndex);
        int bottomLine = richTextBox1.GetLineFromCharIndex(bottomIndex);

        int start = richTextBox1.GetFirstCharIndexFromLine(topLine);
        int end = richTextBox1.GetFirstCharIndexFromLine(bottomLine);

        int numLinesDisplayed = (bottomLine - topLine) + 2;
        richTextBox1.Focus();
        richTextBox1.Select(start, end);

© Stack Overflow or respective owner

Related posts about c#

Related posts about richtextbox