locked
how to reduce flickering when move panel in user control with C#? RRS feed

  • Question

  • hi
    i'm developing a user control in .net 2.0
    now i add a panel to user control, draw the figure on the panel and set its the backcolor property 'transparent'.
    when i move the panel with dragging, flickering happen.

    how can i avoid this problem?
    • Moved by Aland Li Friday, September 4, 2009 6:25 AM Cannot decide what kind of the problem. (From:Windows Forms General)
    Wednesday, September 2, 2009 6:26 AM

Answers

  • Hi SK04,

    From my experience, we need to set some styles of the Panel by calling Control.SetStyle method to reduce flicker, especially double buffering.
    This is a code snippet:
        public class NoFlickerPanel : Panel
        {
            public NoFlickerPanel()
            {
                //Enable these styles to reduce flicker
                //1. Enable user paint.
                this.SetStyle(ControlStyles.UserPaint, true);
                //2. Enable double buffer.
                this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
                //3. Ignore a windows erase message to reduce flicker.
                this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);
            }
        }


    These are some documents:
    Control.SetStyle: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.setstyle.aspx.
    Double Buffering: http://msdn.microsoft.com/en-us/library/ms229622(VS.80).aspx.

    Let me know if this helps or not.
    Aland Li 

    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    • Proposed as answer by Aland Li Tuesday, September 8, 2009 2:32 AM
    • Marked as answer by SK04 Wednesday, September 9, 2009 3:02 AM
    Friday, September 4, 2009 8:05 AM

All replies

  • Hi,

    Sorry for moving this thread incorrectly. Can someone help me moving it back? Thanks.

    Regards,
    Aland Li
    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    Friday, September 4, 2009 6:42 AM
  • Hi SK04,

    From my experience, we need to set some styles of the Panel by calling Control.SetStyle method to reduce flicker, especially double buffering.
    This is a code snippet:
        public class NoFlickerPanel : Panel
        {
            public NoFlickerPanel()
            {
                //Enable these styles to reduce flicker
                //1. Enable user paint.
                this.SetStyle(ControlStyles.UserPaint, true);
                //2. Enable double buffer.
                this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
                //3. Ignore a windows erase message to reduce flicker.
                this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);
            }
        }


    These are some documents:
    Control.SetStyle: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.setstyle.aspx.
    Double Buffering: http://msdn.microsoft.com/en-us/library/ms229622(VS.80).aspx.

    Let me know if this helps or not.
    Aland Li 

    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    • Proposed as answer by Aland Li Tuesday, September 8, 2009 2:32 AM
    • Marked as answer by SK04 Wednesday, September 9, 2009 3:02 AM
    Friday, September 4, 2009 8:05 AM
  • Thanks Li,

    Now i tried to use Control.SetStyle method, but it doesn't get better...
    Tuesday, September 8, 2009 3:13 AM
  • i did mistake to implement.. now flickering was reduced!
    Tuesday, September 8, 2009 11:29 AM
  • Actually, just in case you didn't know:  Windows.Forms.Control class exposes a protected property called doublebuffered that decendents can set to true.  this handles the SetStyle calls for you.

    Jaeden "Sifo Dyas" al'Raec Ruiner
    "Never Trust a computer. Your brain is smarter than any micro-chip."
    Friday, October 30, 2009 2:34 PM
  • How to implement this class in our code can u plz tell me how to implement this class in our code.
    Friday, December 10, 2010 11:12 AM
  • Hello Aland Li,

    I am also facing same Problem, after i saw your solution i thought it will help me. But I was wrong. Can you Please give me some more solutions???

    Friday, December 10, 2010 11:24 AM