<p>I want to create a custom control in C#. But every time I have to fully redraw my control, it flickers, even if I use double buffering (drawing to an Image first, and blitting that).</p>

<p>How do I eliminate flicker when I have to fully redraw?</p>

[{'answer_id': 64336, 'author': 'Grokys', 'author_id': 6448, 'author_profile': 'https://Stackoverflow.com/users/6448', 'pm_score': 0, 'selected': False, 'text': "<p>You say you've tried double buffering, but then you say drawing to an Image first and blitting that. Have you tried setting DoubleBuffered = true in the constructor rather than doing it yourself with an Image?</p>\n"}, {'answer_id': 64507, 'author': 'Shaun Austin', 'author_id': 1120, 'author_profile': 'https://Stackoverflow.com/users/1120', 'pm_score': 5, 'selected': True, 'text': "<p>You could try putting the following in your constructor after the InitiliseComponent call. </p>\n\n<pre><code>SetStyle(ControlStyles.OptimizedDoubleBuffer | \n         ControlStyles.UserPaint |\n         ControlStyles.AllPaintingInWmPaint, true);\n</code></pre>\n\n<p>EDIT:</p>\n\n<p>If you're giving this a go, if you can, remove your own double buffering code and just have the control draw itself in response to the appropriate virtual methods being called.</p>\n"}, {'answer_id': 80273, 'author': 'Eric W', 'author_id': 14972, 'author_profile': 'https://Stackoverflow.com/users/14972', 'pm_score': 1, 'selected': False, 'text': '<p>It may be good enough to just call </p>\n\n<pre><code>SetStyle(ControlStyles::UserPaint | ControlStyles::AllDrawingInWmPaint, true);\n</code></pre>\n\n<p>The flickering you are seeing most likely because Windows draws the background of the control first (via WM_ERASEBKGND), then asks your control to do whatever drawing you need to do (via WM_PAINT).  By disabling the background paint and doing all painting in your OnPaint override can eliminate the problem in 99% of the cases without the need to use all the memory needed for double buffering.</p>\n'}, {'answer_id': 358239, 'author': 'Brad Bruce', 'author_id': 5008, 'author_profile': 'https://Stackoverflow.com/users/5008', 'pm_score': 3, 'selected': False, 'text': '<p>I pulled this from a working C# program.  Other posters have syntax errors and clearly copied from C++ instead of C#</p>\n\n<pre><code>SetStyle(ControlStyles.OptimizedDoubleBuffer | \n                        ControlStyles.UserPaint |\n                        ControlStyles.AllPaintingInWmPaint, true);\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/64272', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7305/']