简体   繁体   English

无法完全清除RichTextBox

[英]Can not completely clear richtextbox

I have a RichTextBox onto which I write long lists of data using a simple write method (see down) 我有一个RichTextBox,可以使用简单的write方法在其中写入一长串数据(见下)

I use vertical scrolbar, and writing and clearing is fine. 我使用垂直滚动条,并且书写和清除都很好。 The problem is with new text after clearing the text. 问题出在清除文本后出现新文本。

I use textbox.clear(); 我使用textbox.clear(); which clears the box OK, but when new text arrives, the old (cleared!) text shows up again, followed by the new text. 这将清除“确定”框,但是当收到新文本时,将再次显示旧文本(已清除!),然后显示新文本。

I have also tried: ResetText, Refresh, Update. 我也尝试过:ResetText,刷新,更新。 dispose, Text =" , richTextBox.Document.Blocks.Clear(); (dont have that one). Have also tried new textbox = new textbox, all for no avail. 处理,Text =“,richTextBox.Document.Blocks.Clear();(没有那个)。也尝试过new textbox = new textbox,所有都无济于事。

The text shows again and again, until I reset the application. 文本会一次又一次显示,直到我重置应用程序为止。 I have seen several form threads on that one, but non helped. 我已经看到了其中一个的多个表单线程,但没有帮助。

My guess: I use both scroll bars. 我的猜测:我同时使用两个滚动条。 A scrollbar must have a buffer, The data is kept somewhere in the active scrollbar buffer? 滚动条必须具有缓冲区,数据是否保留在活动滚动条缓冲区中的某处?

Any (good) idea will be blessed. 任何(好)主意都会受到祝福。

This is how I write / erase the text in the richtextbox: (simplified. mainDisplay is a RichTextBox) 这就是我在Richtextbox中写入/擦除文本的方式:(简化。mainDisplay是RichTextBox)

 public void mainDisplayText(string text)
    {
            this.mainDisplay.AppendText(text);
            this.mainDisplay.ScrollToCaret();
    }  

private void btnClear_Click(object sender, EventArgs e)
    {
       //Have tried all these options:
        this.mainDisplay.Text = "";  //or
        this.mainDisplay.Clear();    //or
        this.mainDisplay.SelectAll();     //or
        this.mainDisplay.SelectedText = "";
    }

You're reusing the same string, so: 您正在重复使用相同的字符串,因此:

this.mainDisplay.Clear();
text = string.Empty;

Should do the trick :) 应该做的把戏:)

Strange indeed. 确实很奇怪。 Could this be some issue in .net 4.7.x ? 这可能是.net 4.7.x中的问题吗? Since last week I compile everything in 4.7.2 and this problem has surfaced here also. 自上周以来,我编译了4.7.2中的所有内容,并且此问题也在这里浮出水面。 Clear() seems to bring back the .Text content. Clear()似乎带回了.Text内容。 So a Clear() after Text="" does not work. 因此 Text =“” 之后的Clear()不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM