我有一个标签,它根据RichTextBox上的文本标记行号。我已经挂钩了Vscroll的事件来处理标签。禁用Richtextbox上的平滑滚动
private void rtbLogicCode_VScroll(object sender, EventArgs e)
{
Point pt = new Point(0, 1);
int firstIndex = rtbLogicCode.GetCharIndexFromPosition(pt);
int firstLine = rtbLogicCode.GetLineFromCharIndex(firstIndex);
pt.X = ClientRectangle.Width;
pt.Y = ClientRectangle.Height;
int lastIndex = rtbLogicCode.GetCharIndexFromPosition(pt);
int lastLine = rtbLogicCode.GetLineFromCharIndex(lastIndex);
// Small correction
if (rtbLogicCode.Text.EndsWith("\n"))
lastLine++;
labelLogicCode.ResetText();
LabelLineNum(firstLine+1,lastLine);
}
#endregion
private void LabelLineNum(int startNum, int lastNum)
{
labelLogicCode.Font = UIConstant.DDCLogicCodeFont;
for (int i = startNum; i < lastNum; i++)
{
labelLogicCode.Text += i + Environment.NewLine;
}
}
一切似乎除了RichTextBox的使用平滑滚动功能,它搞砸了我的行号在许多情况下,用户一路尚未滚动到下一行的正常工作。这会导致行号与RichTextBox上显示的实际文本不同步。
最后,我需要禁用平滑滚动功能来完成此操作。我被告知你可以重写RichTextBox的postMessage API以禁用所提到的功能,但是在搜索了很多文档后,我找不到任何好的文档。
我将不胜感激尽可能详细的解决方案,如何禁用平滑滚动功能。谢谢。
不回答你的问题,但是从长远来看,更先进的编辑控制可能是为了... [Scintilla的(HTTP:// scintillanet .codeplex.com /)是一种可能性。 –
您无法关闭此功能。 –
'See this' - http://stackoverflow.com/a/4920372/763026'&this' - http://www.codeproject.com/Articles/7830/Scrolling-A-round-with-the-RichTextBox-Control –