How to prevent a Windows Forms TextBox from flickering on resize?

Roman Starkov picture Roman Starkov · Aug 26, 2009 · Viewed 15.3k times · Source

There are plenty of articles addressing flicker in Windows Forms. The majority recommend setting DoubleBuffered = true or setting a bunch of ControlStyle flags. However, none of these help reduce a TextBox flickering.

Here are a couple of related questions:

To reproduce the issue, create a new WinForms project, add a TextBox, enable multi-line, disable word-wrap, add a bunch of text, set Anchor to Left+Right+Top+Bottom. Now run and resize. The text flickers. For text boxes inside a couple of nested TableLayoutPanels the flicker on resize is even worse.

Applying the solutions proposed in the above questions at best do not fix the flicker; if I get experimental and set the protected ControlStyle on TextBox I can break it completely (by enabling UserPaint) but not eliminate the flicker.

So, is there any way at all to fix the flickering of the text in a TextBox?

Answer

miasbeck picture miasbeck · Apr 15, 2011

I usually use a RichTextBox instead of a multiline TextBox. By setting the DetectUrls- and ShortcutsEnabled-properties to false the RTB behaves very similar to a TextBox and ... it's flicker-free.