Panel Double buffering VB.NET and C# - Flicker Free

Posted by VIJI Monday, April 19, 2010

I faced a problem when loading background image in the panel. It used to flicker a lot. I thought of double buffering concept. But there is no in-built double buffering property for panel.

All what I did is to write a class which inherits from Panel Class, and in the constructor  set the DoubleBuffered to true and set the appropriate control styles.

VB.NET Code

Public Class DoubleBufferPanel

Inherits Panel


Public Sub New()


Me.DoubleBuffered = True

SetStyle(ControlStyles.AllPaintingInWmPaint Or _

ControlStyles.DoubleBuffer Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint, True)

UpdateStyles()


End Sub
End Class

 
After building the project, we should be able to see the DoubleBufferPanel component in the ToolBox.

Double buffer Panel


Then drag and drop the panel  and used it. The problem is solved. It's so simple.

C# Code

public class DoubleBufferPanel : Panel
{


public DoubleBufferPanel()
{


// Set the value of the double-buffering style bits to true.
   this.DoubleBuffered = true;



   this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint |
    ControlStyles.AllPaintingInWmPaint,true);


    this.UpdateStyles();


}


}

14 Responses to Panel Double buffering VB.NET and C# - Flicker Free

  1. Carrigan Says:
  2. How come I get a 'no source code available' tab and my application breaks?

     
  3. Anonymous Says:
  4. a great thread ;) thank you sooo much!!!

     
  5. Anonymous Says:
  6. Thanks for this.

     
  7. Anonymous Says:
  8. You have NO IDEA of how much you've helped me out by sharing this... kudos!

     
  9. Anonymous Says:
  10. Dude, you rock. Thank you for this.

     
  11. This is fantastic, thank you!

     
  12. Anonymous Says:
  13. Legend, Thanks a lot.

     
  14. Anonymous Says:
  15. Nice!

     
  16. Anonymous Says:
  17. fantastic works perfectly

     
  18. Anonymous Says:
  19. Thank You!!

     
  20. Anonymous Says:
  21. merci beaucoup

     
  22. Anonymous Says:
  23. efkaristo

     
  24. Juliano Lima Says:
  25. Thanks

     
  26. dugernaut Says:
  27. Thanks. I've been looking for a solution for days. This worked great, and so simple - once you know how it's done of course! Cheers!

     

Post a Comment