1

I made a user control, and it was flickering. So, I enabled double buffering. It still flickers. Why?

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
leo60228
  • 754
  • 11
  • 21
  • Did you also double-buffer the parent form? Or, where did you enable the double buffer? You gotta give us something to work with here. Minimal code sample that recreates the problem would be nice. – Paul Sasik Sep 01 '14 at 01:13
  • @PaulSasik Only the element. Is that the problem? *tests* No, it isn't. – leo60228 Sep 01 '14 at 01:15
  • Yeah. Set it on the parent form. It's been years since I dealt with it but double buffering controls in certain container situations can be challenging. So, set the parent form to double buffer and please also share the code with which you set the control to double buffer. Your post will keep drawing downvotes otherwise. – Paul Sasik Sep 01 '14 at 01:17
  • I just set the property in the UI. Nothing special. – leo60228 Sep 01 '14 at 01:18
  • OK. Have you tried the parent form? – Paul Sasik Sep 01 '14 at 01:19
  • Yes, I have, same way. – leo60228 Sep 01 '14 at 01:21
  • ok. You're not actually setting double buffering. Take a look at this post and answers: http://stackoverflow.com/questions/76993/how-to-double-buffer-net-controls-on-a-form There are several ways to do it to a user control and `DoubleBuffer = true;` is not one of them... – Paul Sasik Sep 01 '14 at 01:23
  • @PaulSasik How do I translate that into VB.NET? – leo60228 Sep 01 '14 at 01:27
  • You really need to try and google for some of this stuff. And besides, translating those calls to VB should be simple. Please do yourself a favor and don't just copy/paste code you find online. Try and understand it. I am moving on. Good luck. – Paul Sasik Sep 01 '14 at 01:31

1 Answers1

2

Just add this to the form's code:

Protected Overrides ReadOnly Property CreateParams() As CreateParams
    Get
        Dim cp = MyBase.CreateParams
        cp.ExStyle = cp.ExStyle Or &H2000000
        ' Turn on WS_EX_COMPOSITED
        Return cp
    End Get
End Property
leo60228
  • 754
  • 11
  • 21
  • You need to know that trick is the badest idea (something that anybody tells, people just copy, paste, and use without investigate what are they doing exactly). Setting that style will SLOW the general performance/speed of the element in more than 50%, if you set that style in a form then all the controls inside will be affected to that performance reduction. if you want to avoid flickering 100% then just don't use WinForms. – ElektroStudios Sep 01 '14 at 01:38
  • 1
    @ElektroStudios *avoid flickering 100% then just don't use WinForms* is a very strong statement. You can have a flicker free winform. You just have to know what you are doing. eg A little style `WS_CLIPCHILDREN` can save you from a lot of headaches. – γηράσκω δ' αεί πολλά διδασκόμε Sep 01 '14 at 01:50