Stop repaint of RichTextBox?

G

Grant Schenck

I have code where I append text to a rich text box. I grab the current
SelectionStart and SelectionLength before I append the text and then after I
reset the SelectionStart and SelectionLength to their former values. I then
do a ScrollToCaret() to insure that the selection still shows on the screen
(because the append text moves it.)

Now, it all works but I get a noticible flash as I append the text and
apparently the control updates.

So, is there some way to stop the control updating until I'm all done?

Thanks,

Grant Schenck
 
K

Kevin Yu [MSFT]

Hi Grant,

It seems there is no way out except calling SuspendLayout() to prevend
re-drawing during updating.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
I

Iwan Petrow

Hi,

Try to remove the focus from the rtf control, do your changes and set
the focus again on the rtf control (you have to save the cursor
position and set it too at the end).
 
J

Jeffrey Tan[MSFT]

Hi Grant,

Thanks for your post.

Yes, SuspendLayout is just used to suspend the layout of the controls, such
as size changing, location changing. It can not disable the paiting and
scrolling in textbox.

I do not think there is any way to append the text into the textbox without
it being scrolling. Winform AppendText method internally sends
EM_REPLACESEL to the textbox.
But in win32 world, EM_REPLACESEL message will cause the scrolling to the
end out of our control. Also, SetWindowText win32 API will also cause the
scrolling to the top.

Based on my test, the scrolling flash only occurs when we add the text in
high frequency. I think you may cache multi-adding operations in a private
field, then add the text in a longer interval. This should reduce the
flashing in your application.

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
D

Dmytro Lapshyn [MVP]

Everyone,

The LockWindowUpdate API function prevents a window from being redrawn. The
original poster can try it to reduce the flashing.
 
G

Grant Schenck

I ended up sending a WM_SETREDRAW via SendMessage to disable then reenable
followed by an Invalidate() after I finished updating. That seemed to work.

Thanks all who answered.

Grant

Dmytro Lapshyn said:
Everyone,

The LockWindowUpdate API function prevents a window from being redrawn. The
original poster can try it to reduce the flashing.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


"Jeffrey Tan[MSFT]" said:
Hi Grant,

Thanks for your post.

Yes, SuspendLayout is just used to suspend the layout of the controls,
such
as size changing, location changing. It can not disable the paiting and
scrolling in textbox.

I do not think there is any way to append the text into the textbox
without
it being scrolling. Winform AppendText method internally sends
EM_REPLACESEL to the textbox.
But in win32 world, EM_REPLACESEL message will cause the scrolling to the
end out of our control. Also, SetWindowText win32 API will also cause the
scrolling to the top.

Based on my test, the scrolling flash only occurs when we add the text in
high frequency. I think you may cache multi-adding operations in a private
field, then add the text in a longer interval. This should reduce the
flashing in your application.

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Grant and "Dmytro Lapshyn [MVP]"

Oh, yes, it seems that both LockWindowUpdate and WM_SETREDRAW with wParam
set to false will prevent the TextBox from updating untill we release the
lock. Thank you for sharing the solution with the community. But, if we do
not want to update the UI immediately, I think it is better for us to cache
multi-updating, then update the textbox at a time. This should have the
same effect as locking the UI drawing.

Anyway, we have several different approaches to resolve this problem :).
If you have any further concern, please feel free to post. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top