如何在c#中双重缓冲RichTextBox?

时间:2021-11-07 16:02:54

Probably not double buffering but I'm trying to make a highlighter (pure amusement) using a RichTextBox. The problem I have is that, when there are a lot of highlighted words, programmer-made flickering appear and even see the textbox scroll.

可能不是双缓冲,但我正在尝试使用RichTextBox制作荧光笔(纯粹娱乐)。我遇到的问题是,当有很多突出显示的单词时,会出现程序员制作的闪烁,甚至会看到文本框滚动。

I don't think that RichTextBox has DoubleBuffered property, and even if it had, it wouldn't word, the flickering is my fault.

我不认为RichTextBox具有DoubleBuffered属性,即使它有,它也不会说,闪烁是我的错。

2 个解决方案

#1


int pos = myTextBox.SelectionStart;
RichTextBox buffer = new RichTextBox();
buffer.Rtf = myRichTextBox.Rtf;

//Do whatever you wanna do in buffer


myTextBox.Rtf = buffer.Rtf;
myTextBox.SelectionStart = pos;
myTextBox.SelectionLength = 0;

Tho, I still have a problem because, no matter what I do, myTextBox.ZoomFactor seems to be deleted.

所以,我仍然有一个问题,因为无论我做什么,myTextBox.ZoomFactor似乎都被删除了。

#2


Just use LockWindowUpdate on your RichTextBox before changing the color.

在更改颜色之前,只需在RichTextBox上使用LockWindowUpdate。

#1


int pos = myTextBox.SelectionStart;
RichTextBox buffer = new RichTextBox();
buffer.Rtf = myRichTextBox.Rtf;

//Do whatever you wanna do in buffer


myTextBox.Rtf = buffer.Rtf;
myTextBox.SelectionStart = pos;
myTextBox.SelectionLength = 0;

Tho, I still have a problem because, no matter what I do, myTextBox.ZoomFactor seems to be deleted.

所以,我仍然有一个问题,因为无论我做什么,myTextBox.ZoomFactor似乎都被删除了。

#2


Just use LockWindowUpdate on your RichTextBox before changing the color.

在更改颜色之前,只需在RichTextBox上使用LockWindowUpdate。