我正在使用代码编辑器(winforms)
我正在使用类似这样的标签在 countline 上工作:
http://oi42.tinypic.com/iypoub.jpg
使用此代码:
private void timer_countline_Tick(object sender, EventArgs e)
{
updateNumberLabel();
}
private void updateNumberLabel()
{
//we get index of first visible char and number of first visible line
Point pos = new Point(0, 0);
int firstIndex = rtb.GetCharIndexFromPosition(pos);
int firstLine = rtb.GetLineFromCharIndex(firstIndex);
//now we get index of last visible char and number of last visible line
pos.X = ClientRectangle.Width;
pos.Y = ClientRectangle.Height;
int lastIndex = rtb.GetCharIndexFromPosition(pos);
int lastLine = rtb.GetLineFromCharIndex(lastIndex);
//this is point position of last visible char, we'll use its Y value for calculating numberLabel size
pos = rtb.GetPositionFromCharIndex(lastIndex);
//finally, renumber label
numberLabel.Text = "";
for (int i = firstLine; i <= lastLine + 1; i++)
{
numberLabel.Text += i + 1 + "\n";
}
}
计时器将间隔设置为 1 。标签码头=左。现在的问题是每次我运行程序时,标签都会不停地闪烁。即使我改变间隔仍然是同样的事情。
但是当我将 updateNumberLabel() 转移到 textchange 事件时,每次我在richtextbox 上添加一个字符或按空格时它仍然会闪烁。
像这样: http: //oi40.tinypic.com/a43gcy.jpg
现在我的问题是如何避免这种情况?或者我可以做些什么来避免更新时整个标签的闪烁?
非常感谢您的帮助!