我有一個標籤,它根據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 –