Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用定时器控制避免标签闪烁_C#_Timer_Label - Fatal编程技术网

C# 使用定时器控制避免标签闪烁

C# 使用定时器控制避免标签闪烁,c#,timer,label,C#,Timer,Label,我正在使用代码编辑器(winforms) 我在countline上工作时使用的标签如下: 使用此代码: private void timer_countline_Tick(object sender, EventArgs e) { updateNumberLabel(); } private void updateNumberLabel() { //we get index of first vi

我正在使用代码编辑器(winforms)

我在countline上工作时使用的标签如下:

使用此代码:

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";
            }

        }
private void timer\u countline\u Tick(对象发送方,事件参数e)
{
updateNumberLabel();
}
私有void updateEnumBerLabel()
{
//我们得到了第一个可见字符的索引和第一个可见行的数目
点位置=新点(0,0);
int firstIndex=rtb.GetCharIndexFromPosition(pos);
int firstLine=rtb.GetLineFromCharIndex(firstIndex);
//现在我们得到最后一个可见字符的索引和最后一个可见行的数目
位置X=ClientRectangle.宽度;
位置Y=斜交角高度;
int lastIndex=rtb.GetCharIndexFromPosition(pos);
int lastLine=rtb.GetLineFromCharIndex(lastIndex);
//这是最后一个可见字符的点位置,我们将使用它的Y值来计算numberLabel大小
pos=rtb.GetPositionFromCharIndex(最新索引);
//最后,重新编号标签
numberLabel.Text=“”;

对于(inti=firstLine;i您可以从启用双缓冲中获益,无论是在标签级别还是表单级别


这里有两个例子:.

闪烁是指闪烁?还是稳定闪烁?@cokeman19在我使用计时器时闪烁很快…我传递到textchange事件的时间闪烁我在RichTextBox上添加文本的时间您可能会从启用双缓冲中获益,无论是在标签级别还是在表单级别。有这里有两个例子:.@cokeman19您的权利,先生……关于停靠,但问题是我仍然不能使用splitcontainer。我已经按照公认的答案做了,但它仍然闪烁nonstop@cokeman19成功了…请回答,我会接受的,先生,非常感谢!