【发布时间】:2010-05-12 01:31:00
【问题描述】:
好的,我试图在 Richtextbox 中突出显示关键字,问题是我的代码仅突出显示 textChanged 事件上的可见文本,所以我尝试将代码放在richtextbox VScroll 中,所以当我向上滚动时会突出显示以前不可见的文本,但是每次我开始滚动时都会收到此错误:“System.Windows.Forms.dll 中发生了'System.StackOverflowException'类型的未处理异常” 有人知道为什么吗?或者也许我可以在滚动时突出显示单词? 谢谢,坦纳。
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);
【问题讨论】:
-
一般提示:堆栈溢出几乎总是由无限递归引起的。
标签: c# syntax richtextbox syntax-highlighting