C# RichTextBox更改字母颜色-速度问题

C# RichTextBox更改字母颜色-速度问题,c#,C#,我的档案是450503个字母的文本。我必须在另一个字母上更改每个字母(例如“b”-用户选择),并用设置的红色标记它。 当我这样做的时候: for(int i=0; i<lenght; ++i) { this.rtb.Select(i, 1); this.rtb.SelectionColor = Color.Red; this.rtb.SelectedText = this.rtb.SelectedText; this.rtb.DeselectAll();

我的档案是450503个字母的文本。我必须在另一个字母上更改每个字母(例如“b”-用户选择),并用设置的红色标记它。 当我这样做的时候:

 for(int i=0; i<lenght; ++i) {
    this.rtb.Select(i, 1);
    this.rtb.SelectionColor = Color.Red;
    this.rtb.SelectedText = this.rtb.SelectedText;
    this.rtb.DeselectAll();
 }

for(inti=0;i这是因为每次发生时都要强制它重新绘制


将其包装在
SuspendLayout
resumeloayout
中,这是因为每次发生时,您都会强制它重新绘制


在运行逻辑之前,请尝试调用
rtb.SuspendLayout();
,然后再调用
rtb.SuspendLayout();
,将其包装在
SuspendLayout
resumellayout
中。如下所示:

rtb.SuspendLayout();

for(int i=0; i<lenght; ++i) {
    this.rtb.Select(i, 1);
    this.rtb.SelectionColor = Color.Red;
    // you shouldn't need these lines:
    // this.rtb.SelectedText = this.rtb.SelectedText;
    // this.rtb.DeselectAll();
 }

rtb.ResumeLayout();
rtb.SuspendLayout();

对于(int i=0;i请在运行逻辑之前尝试调用
rtb.SuspendLayout();
,然后再调用
rtb.resumeloayout();
。如下所示:

rtb.SuspendLayout();

for(int i=0; i<lenght; ++i) {
    this.rtb.Select(i, 1);
    this.rtb.SelectionColor = Color.Red;
    // you shouldn't need these lines:
    // this.rtb.SelectedText = this.rtb.SelectedText;
    // this.rtb.DeselectAll();
 }

rtb.ResumeLayout();
rtb.SuspendLayout();

对于(int i=0;我现在记不清了,但不是有两种方法,比如rtb.BeginUpdate和End或ResumeUpdate吗?
this.rtb.SelectedText=this.rtb.SelectedText
?Windows程序员只需在rich edit窗口中触发消息,然后在每次点击后发送消息。毫无疑问,有一个.net等价物。它会在winforms answers中,Suspend/ResumeLayout具有持久的神秘性。真正的答案是:非常感谢。一切都很好。现在记不清了,但不是有两种方法,如rtb.BeginUpdate和End或ResumeUpdate吗?this.rtb.SelectedText=this.rtb.SelectedText
?Windows prGrammer只需在rich edit(富编辑)窗口中发送消息,然后在每次点击后发送消息。毫无疑问,有一个与.net等效的。这将在几秒钟内完成。Suspend/ResumeLayout在winforms answers中具有持久的神秘性。真正的答案是:非常感谢。一切都很好。