为什么有时richTextBox会闪烁?

时间:2012-09-02 22:10:39

标签: c#

我在richTextBox中更新了两个变量,因为每次我对richTextbox执行Clear()时都不希望它移动到新行。 但是richextBox中的每隔几秒就像清除它时闪烁一样。 在使用Clear()之前:richTextBox1.Text =“”;但它给出了相同的结果。

有什么办法可以避免吗?

private void timer1_Tick(object sender, EventArgs e)
        {
            richTextBox1.Clear();
            memUsage = theMemCounter.NextValue();
            label1.Text = memUsage.ToString();
            Logger.Write("Memory Usage   " + memUsage.ToString());
            AppendText(richTextBox1, "Memory Usage   " + memUsage.ToString() + Environment.NewLine, Color.Red);
            cpuUsage = this.theCPUCounter.NextValue();
            label2.Text = cpuUsage.ToString();
            Logger.Write("Cpu Usage   " + this.cpuUsage.ToString());
            AppendText(richTextBox1, "Cpu Usage   " + cpuUsage.ToString() + Environment.NewLine, Color.Blue);
            Values.Add(cpuUsage);
            isProcessRunning();
            if (alreadyRun == true)
            {
                processValues.Add(cpuUsage);
            }

        }

也许我应该使用其他东西然后使用richTextBox?我使用richTextBox为里面的文本着色。

这是AppendText函数:

public  void AppendText( RichTextBox box, string text, Color color)
        {
            box.SelectionStart = box.TextLength;
            box.SelectionLength = 0;

            box.SelectionColor = color;
            box.AppendText(text);
            box.SelectionColor = box.ForeColor;
        } 

0 个答案:

没有答案
相关问题