1

I have created a user control where I'm using single Graphics.DrawImage() to paint the entire content of the control. "Painting couldn't be simpler" I thought "so the flickering should be definitely elliminated." But the flickering on repaint is still there until I set DoubleBuffered property to true.

Why setting of DoubleBuffered = false is offered as default value if it leads to flicker even in case of most trivial painting? Why they didn't lock painting mechanism at double buffering permanently? Is there a use case where DoubleBuffered = false makes sense?

miroxlav
  • 11,796
  • 5
  • 58
  • 99

2 Answers2

1

All Standard .NET Framework Controls are double buffered by default.

When you create your own controls with custom paint logic, you can specify if you want use double buffering provided by the .NET Framework (DoubleBuffered = true or SetStyle(ControlStyles.OptimizedDoubleBuffer, true)) or not.

For you own controls, you should set it to false if you want to use your own double buffering logic (specially for animation or advanced memory management) that mostly involves the class BufferedGraphicsContext.

Heres a link to the MSDN describing Double Buffered Graphics in more detail

Jehof
  • 34,674
  • 10
  • 123
  • 155
  • Thank you for the answer. So if I understand correctly, `DoubleBuffered = false` is a corner case for those who want to implement their own double buffering logic and *default* setting of `DoubleBuffered` to `false` is most likely a mistake of .NET control designers (assuming they usually set default values of controls to most convenient ones). – miroxlav Jul 08 '15 at 07:01
  • @miroxlav Not each custom control needs double buffering. Double Buffering requires more memory. If you need Double Buffering you have two options. Use the default of the .NET Framework (DoubleBuffered = true) or implement your own and leave DoubleBuffered as false. – Jehof Jul 08 '15 at 07:09
  • You say "Not each custom control needs DB". But I have verified that *even trivial painting requires the DB*. (Either that DB from .NET or own.) So how "not each"? Is the logic that DB is `false` by default because we assume that *by default most devs will implement their own DB* (involving `BufferedGraphicsContext`)? Because I don't think that most devs implement their own DB when going to quickly create their own control. I quickly created a control and having default deal-breaker present (DB = `false`), the control just confused me with flickering issues. What a weird default setting... – miroxlav Jul 08 '15 at 07:37
  • @miroxlav with "need" I mean that it is sometimes acceptable that a control flickers. – Jehof Jul 08 '15 at 07:46
1

Summary

To compile outcomes from the answer I accepted (and from the discussion below it),
setting of DoubleBuffered to false makes sense when:

  • you implement your own double buffering (involving class BufferedGraphicsContext)

  • it does not matter whether the control flickers

Similar answer: Why is DoubleBuffered disabled by default? (It is for forms, but it applies also to controls.)

Community
  • 1
  • 1
miroxlav
  • 11,796
  • 5
  • 58
  • 99