Turn off screen updating while I fill a RichTextBox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am filling a richtextbox via the AppendText method and it works great.
However, I would like to to off screen updating, add my 50 or so lines to the
richtextbox, and then turn screen updating back on.

How do I do this? SuspendLayout does not do this.

Thanks.
 
Hi Dave,

You can use WM_SETREDRAW message to do this. Refer to following FAQ entry:

#Windows Forms FAQ - Windows Forms
http://msdn2.microsoft.com/en-us/netframework/aa497373.aspx
How do I suspend painting a form until all its controls are initialized?

There is not currently a way to do this built into the framework, but
WM_SETREDRAW will do what you're looking for:

[ DllImport( "user32" ) ]
private static extern bool SendMessage( IntPtr hWnd, int msg,
int wParam, int lParam );
private const int WM_SETREDRAW = 0xB;

int paintFrozen;

private bool FreezePainting
{
get { return paintFrozen > 0; }
set
{
if ( value && IsHandleCreated && Visible )
if ( 0 == paintFrozen++ )
SendMessage( Handle, WM_SETREDRAW, 0, 0 );

if ( !value )
{
if ( paintFrozen == 0 ) return;
if ( 0 == --paintFrozen )
{
SendMessage( Handle, WM_SETREDRAW, 1, 0 );
Invalidate( true );
}
}
}
}


Hope this helps.


Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Dave,

Does the above suggestion work for you? Please feel free to let me know if
there's anything unclear. Thanks.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top