C# 为什么richTextBox有时会闪烁?
我在richTextBox中更新了两个变量,因为我不希望每次我对richTextBox执行Clear()时它都移动到新行。 但是在richextBox中每隔几秒钟就好像在清除它时闪烁一样。 在Clear()之前,我使用了:richTextBox1.Text=“”;但结果是一样的 有什么办法可以避免吗C# 为什么richTextBox有时会闪烁?,c#,C#,我在richTextBox中更新了两个变量,因为我不希望每次我对richTextBox执行Clear()时它都移动到新行。 但是在richextBox中每隔几秒钟就好像在清除它时闪烁一样。 在Clear()之前,我使用了:richTextBox1.Text=“”;但结果是一样的 有什么办法可以避免吗 private void timer1_Tick(object sender, EventArgs e) { richTextBox1.Clear();
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;
}
取决于AppendText()方法的作用。是否有耗时的代码?或者可能是不断重新绘制的问题。
AppendText
方法在做什么?你能给我们看一下代码吗?尼古拉,我刚刚在我的问题中添加了文本代码。请尝试将表单的双缓冲
属性设置为true