none
Flicker-free painting

    Question

  • A frequently heard complaint at this forum is Windows Forms' tendency to cause "flicker" on forms with a lot of controls.  There are two causes for this kind of flicker:

    1. Windows sends a control two messages when a control needs to be painted.  The first one (WM_ERASEBKGND) causes the background to be painted (OnPaintBackground), the second causes the foreground to be painted (WM_PAINT, firing OnPaint).  Seeing the background drawn first, then the foreground is noticeable when the drawing is slow.  Windows Forms has a ready solution for this kind of flicker with ControlStyles.OptimizedDoubleBuffer.

    2. A form that has a lot of controls takes a long time to paint.  Especially the Button control in its default style is expensive.  Once you get over 50 controls, it starts getting noticeable.  The Form class paints its background first and leaves "holes" where the controls need to go.  Those holes are usually white, black when you use the Opacity or TransparencyKey property.  Then each control gets painted, filling in the holes.  The visual effect is ugly and there's no ready solution for it in Windows Forms.  Double-buffering can't solve it as it only works for a single control, not a composite set of controls.

    I discovered a new Windows style in the SDK header files, available for Windows XP and (presumably) Vista: WS_EX_COMPOSITED.  With that style turned on for your form, Windows XP does double-buffering on the form and all its child controls.  This effectively solves the 2nd cause of flicker.  Here's an example:

    using System;
    using System.Drawing;
    using System.Windows.Forms;

    namespace WindowsApplication1 {
      public partial class Form1 : Form {
        public Form1() {
          InitializeComponent();
          for (int ix = 0; ix < 30; ++ix) {
            for (int iy = 0; iy < 30; ++iy) {
              Button btn = new Button();
              btn.Location = new Point(ix*10, iy*10);
              this.Controls.Add(btn);
            }
          }
        }
        protected override CreateParams CreateParams {
          get {
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x02000000;
            return cp;
          }
        }
      }
    }

    To see it at work, minimize and restore the form and observe its painting behavior.  Comment the cp.ExStyle assignment to see the difference.  All you have to do to use this in your own form is to copy and paste the CreateParams property.

    Some caveats with this: this doesn't speed up the painting.  Your form just stays invisible while painting is taking place, then pops on the screen when it is done.  And it doesn't work when you use the Opacity or TransparencyKey property, the form outline will be visible as an ugly black rectangle while painting takes place.  The best solution for that is to use a timer to increment the Opacity value to 99% to make the form visible after it is painted.

    I haven't experimented a great deal with this as yet, please post to this thread if you have problems using it.
    Thursday, August 23, 2007 12:11 PM
    Moderator

All replies

  • Under the .NET framework 2.0 you can simply use

    class Form1 : Form {
      Form1(){
       this.doublebuffered = true;
      }
    }
    Tuesday, August 28, 2007 6:02 AM
  •  

    yes thats true, no need to double buffer PictureBox as its already double bufferd (for the OnPaint)!
    Tuesday, August 28, 2007 3:17 PM
  • Both responses are covered by item #1 in my post.  Be sure to run the sample code to see item #2 getting fixed.  If WF's double-buffering solves your problem, this thread is not relevant to you.  It is only relevant to programmers that have a lot of controls on their forms.
    Tuesday, August 28, 2007 9:35 PM
    Moderator
  • Here is some equivalent VB code

     

    Code Snippet

    Public Class Form1

      Private Sub FormStd_Load( _

          ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

     

        ' Add a bunch of command buttons.
        For outer As Integer = 0 To 29
          For inner As Integer = 0 To 29
            Dim btn As New Button()
            btn.Location = New Point((outer * 10) + 10, (inner * 10) + 10)
            Me.Controls.Add(btn)
          Next
        Next

      End Sub 'Form1_Load

     

      Protected Overrides ReadOnly Property CreateParams() As CreateParams
        Get
          Dim cp As CreateParams = MyBase.CreateParams
          cp.ExStyle = cp.ExStyle Or &H2000000
          Return cp
        End Get
      End Property 'CreateParams

    End Class

     

    Friday, August 31, 2007 10:42 PM
  • Thanks.
    Friday, August 31, 2007 10:46 PM
    Moderator
  • I tried your code in a project I am working on.  I have created my own suite of controls with special painting in the border areas.  When I load my form with about 60 controls on it, it works in that the form doesn't show until all the child controls have been painted too.  But all my custom paint routines are ignored.  Just thought I'd pass this along.

     

    Tony

     

    Sunday, September 02, 2007 12:48 PM
  • Thanks for the feedback.  Should be an improvement, still.  Are you using the Paint event?
    Sunday, September 02, 2007 9:40 PM
    Moderator
  • In my project I use DotNetBar controls. I placed your code in a form and I had the same problem. Many areas remained unpainted (many black areas).
    Wednesday, September 05, 2007 7:02 AM
  • I too am having a problem.  I have a panel that custom paints its background color.  My panel has a picturebox, label and a second panel in it.  All of the controls have their background color set to transparent.  The picturebox and label both paint correctly.  The second panel does not.  It is the color of the form's background. 

    Wednesday, September 05, 2007 8:42 PM
  • This solution doesn't aim to make 3rd party controls paint properly.  Nor solve classic transparency problems.  I'll switch my invitation to post and ask for success stories now.
    Thursday, September 06, 2007 12:25 AM
    Moderator
  • Thank you so much, nobugz, this is fantastic. Works very well with my form with treeview and a panel with DataGridView and ListView. When switching Panel contents I had to implement this: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1322708&SiteID=1

     

    (I was clearing and then addding to the panel, which caused parts of the previous control to be visible on the new control)

    Thursday, September 06, 2007 1:31 PM
  • Wow! you rock!

     

    Thanks fot the tips... the second solution solved my problem!

     

    Thursday, September 06, 2007 3:25 PM
  • Dear All,

    I didn't understund how it helps you, when in my project it doesn't helps any more. It is very serious problem in .Net Framework and I tried everything...

    I have one User control which has 50 buttons and has background image. I don't wont to use Opasity feature because of requirements. I think this is a serious BUG in .NET framework!!!

    If I am trying to write the same control in VB6.0 it works without any flickering...

    So dear .Net Team please think about this ...

    Thanks,
    Vasil Mamikonyan


    Monday, September 17, 2007 1:02 PM
  •  

    hi,

    i also think it's big PROBLEM that actually looks more like a bug or missfunctionality. it seems system invokes redraw INSTANTLY after ANY changes related to controls. not after ALL gui changes are made. and SuspendLayout() it's only about events and nosence drawing. so there is no way to tell system "hey, wait a bit".

    am i wrong? does anybody know how it working internally? i have my approach from "playing" with simple example nearly same above. my with small discussion around:

    http://www.codeproject.com/script/comments/forums.asp?forumid=387161&select=2230099&exp=0&df=100#xx2230099xx

     

    thanks,

    all the best.

    Monday, September 17, 2007 4:27 PM
  • Hi,

     

    Thanks for your replay you are right! but unfortunately I didn't found any solution for that 

    I think we should use ASP.NET for this situation and never use WinFormsSmile

     

    Thanks,

    Vasil Mamikonyan

    Wednesday, September 19, 2007 12:43 PM
  • this was actually a useful bit of information. Do you have an idea of how much it might slow down the painting? I have currently about 30 controls on a dialog I am implementing which is similar to the notification window in Outlook. I absolutely do not want any flicker, but do not want to slow down the painting a lot either.

     

    thanks,

    Swaha

    Friday, October 05, 2007 9:51 PM
  • I don't know if this will help your specific situation, but you can suspend and resume the drawing of any control using win32 methods as shown below - I've wrapped these in helper methods to prevent code analysis from complaining, and put them in a class full of Win32 stuff... 

     

    public sealed class NativeMethods

    {

    // ...

     

    public static void SuspendDrawing(Control c)

    {

    if (c == null)

    throw new ArgumentNullException("c");

    NativeMethods.SendMessage(c.Handle, (Int32)NativeMethods.WM_Message.WM_SETREDRAW, (Int32)0, (Int32)0);

    }

     

    public static void ResumeDrawing(Control c)

    {

    if (c == null)

    throw new ArgumentNullException("c");

    NativeMethods.SendMessage(c.Handle, (Int32)NativeMethods.WM_Message.WM_SETREDRAW, (Int32)1, (Int32)0);

    c.Refresh();

    }

     

    [DllImport("User32")]

    private static extern IntPtr SendMessage(IntPtr hWnd, Int32 msg, Int32 wParam, Int32 lParam);

     

    // ...

     

    private NativeMethods()

    {

    }

    }

    Wednesday, October 10, 2007 10:01 AM
  • I've been trying to fix the problem described in #2 for years. This works brilliantly. Thank you!!!!

    Sunday, October 14, 2007 9:26 PM
  • Hi,

     

         Thanks a lot , this worked for sure but all the control borders are gone. I have a nested container structure and i set the bottom most container style to wm_ex_composited.The top most container has a datagrid view , with this kind of a style my grid doesn't show the grid lines any longer. I also have a few user controls even there borders are gone.

     

     

    Regards,

    Vijay

    Monday, October 29, 2007 9:31 AM
  • New development.  The CreateParams override does not reduce the flicker in Windows Vista. Instead of the white background as the controls are drawn, the background is black. This is demonstrated by running nobugz' sample code under Vista.

    Summary:

    Windows XP:
    Flickers due to #2 above, CreateParams override fixes it but causes problems with other controls (eg DataGridView borders, Tao OpenGL, and other 3rd party controls)

    Windws Vista:
    Flickers due to #2 above but slightly reduced. Aero seems to reduce the appearance of this flicker. CreateParams override causes flicker similar to that described in #2 with slightly different behavior and perhaps slightly worse that without.

     

     

     

    Monday, October 29, 2007 4:45 PM
  •  

    Hi,

     

          I have a nested container structure and i set the Outer most container style to wm_ex_composited(To remove flickering after seeing Nobugz post http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2044742&SiteID=1 ).The inner most container has a datagrid view , with this kind of window style my grid doesn't show the grid lines any longer. I also have a few user controls with panels docking in them and their borders are gone.I tried painting the panels in their paint events but this also didnt help .The moment i remove  wm_ex_composited window style everything renders fine.

     

    PlZ plz some one help me

     

    Regards,

    Vijay

    Friday, November 02, 2007 5:56 AM
  • ok I have added

     Protected Overrides ReadOnly Property CreateParams() As Windows.Forms.CreateParams
            Get
                Dim cp As Windows.Forms.CreateParams = MyBase.CreateParams
                cp.ExStyle = cp.ExStyle Or &H2000000
                Return cp
            End Get
        End Property 'CreateParams


    in my form and flicker is gone  but the cpu usage is 100%  why is that ?

    I have  override the WinProc to see if there was a  loop on WM_PAINT  but there was no loop so why does my app takes my cpu to  100% ?

    without the CreateParm  it flickers a lot. but cpu is not 100%


    here I see a similar problem  http://cboard.cprogramming.com/showthread.php?t=68235
    but still trying to fix it


    i have like 25 controls on my form   !



    Thanks


    Friday, November 02, 2007 6:58 PM
  • I'm a convert from Delphi and learning C#. While converting a StringGrid to a tablelayoutpanel full of labels the flicker became very noticeable with 130 labels. I tried your solution and it was VERY impressive. Makes the program usable now. 

    Wednesday, November 21, 2007 7:01 PM
  • I tried this on one of my user controls that contains several other user controls. It looked like it worked great but then I scrolled down and noticed some of the controls had weird dark borders, and the datagridview controls had solid black backgrounds. Guess I'll stick w/ the slow piece by piece loading, oh well. Thanks for sharing w/ us.

    Monday, November 26, 2007 7:04 PM
  • Hi.

     

    I also have the same problem with AsimKhan.

    Without WS_EX_COMPOSITED, flicker caused by a lot of child controls bothers me.

    Enabling WS_EX_COMPOSITED ex-style bit makes flicker gone, but it causes 100% cpu load.

     

    Regards.

     

     

    Monday, December 10, 2007 11:15 PM
  • I had spent much time looking for a solution for this problem and hadn't found anything that would work. I even created my own nonflickering control in my despair Wink as I had come to the conslusion this would be the only way to overcome this issue.

    Thank you boys!
    Friday, January 18, 2008 3:54 PM
  • Thanks

    very valuable post
    Thursday, March 13, 2008 3:24 PM
  • hi,

     

    i am relatively new to .net, but have been using vb6 for many years. i am currently transferring one of my programs from vb6 to .net. i couldn't help but notice how long the controls take to load the initial time a form.show() is called. it is really quite ridiculous. whereas in vb6 showing the same exact form is lightning fast.

     

    after reading around on the blogs i managed to find that if i called form.showdialog() the form would show properly;  i.e. shown at once instead of the background painted with a bunch of holes while the controls take longer. the problem with that for me is that the showdialog call shows the form as modal, and i need to do some other stuff in my program while that form is being displayed.

     

    i tried many things, the sleep() function after calling show, double buffering, control.suspendlayout / resumelayout(), using the WS_EX_COMPOSITED create params, etc...the list goes on and on.

     

    for some reason i never thought to allow windows the time to draw the form before running off to do my bidding. i don't know if this will help anyone else but if form.show() is taking a long time try throwing an application.doevents() call right after the show call.

     

    myform.show()

    application.doevents()

     

    and if you really want to make sure windows has enough processor time to concentrate on drawing your form you could take a tip the the directx team and use the peekmessage api:

     

    <System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)> _

    Public Structure MessageStruct

    Public HWnd As IntPtr

    Public Msg As Message

    Public WParam As IntPtr

    Public LParam As IntPtr

    Public Time As Integer

    Public P As System.Drawing.Point

    End Structure

     

    <System.Security.SuppressUnmanagedCodeSecurity()> _

    Public Declare Function PeekMessage Lib "User32.dll" Alias "PeekMessageA" ( _

    ByRef msg As MessageStruct, ByVal hWnd As IntPtr, ByVal messageFilterMin As Integer, _

    ByVal messageFilterMax As Integer, ByVal flags As Integer) As Integer

     

    public sub main()

    Dim myform As New Form

     

    myform.Show()

    Dim msg As MessageStruct

    Do

    Application.DoEvents()

    Loop Until (PeekMessage(msg, IntPtr.Zero, 0, 0, 0) = 0)

     

    '// continue program

    end sub

     

    hope this helps someone else out there. happy programming.

     

    stevinz

    Thursday, March 20, 2008 9:20 PM
  • Great topic, thanks allot.
    Tuesday, April 22, 2008 5:08 AM
  • is microsoft going to do something about this, i had some problems with your code on c# express it ruined my project i have no idea why, and doublebuffer doesn't help at all, i'm testing the code on visual studio pro demo and it seems to work for now, no bugz(i`m talking about code on post number 1)
    Wednesday, May 07, 2008 6:49 AM
  • Im sooo happy!  Days on this and finaly an answer that worked for me!  THANK YOU!!  Want me to mow your lawn?  I will do it!  THANKS!!

     

    -Terence

    Thursday, May 29, 2008 1:29 AM
  • Inv wrote:

    "What about WinAPI function LockWindowUpdate? :

    LockWindowUpdate(Handle of your window) before painting and
    LockWindowUpdate(0) after painting"

    problem is, paint is the last thing that happens, so how do you code for "after painting"?
    Thursday, May 29, 2008 4:06 PM
  • Hi nobugz,

     

          But this param style causes 100% CPU utilization Sad. I am developing win forms application with lots of picture box and panels and controls on it. I have used this style to allow resizing of my form to avoid flickering. But it causes very slow processing of my App and result in 100% CPU utilization. Can anyone suggest any alternative of it or any solution of this problem?

     

    Thanks

    Tuesday, June 10, 2008 9:57 AM
  • That's a really nice solution to avoid flickering. But I am using 6 Datagridviews, Multiple split containers, pictures boxes, comboxes, tree views etc.... on a single tab page of a form. So the problem in Windows XP is after setting the ExStyle property, the grid lines disappear, the splitter lines are also not visible when the splitter is moved. In Vista it is working fine.. Do you have any idea how to use this...?

    Monday, June 16, 2008 5:53 AM
  • the Style can only use on winxp,not support win2k

     

    Tuesday, July 29, 2008 2:55 PM
  • Thank you nobugs, your hint about WS_EX_COMPOSITED worked for my case.

    DoubleBuffered works inside one control to avoid flickering during repaint.

    The WS_EX_COMPOSITED imports the same logic but for container when repainting its indivdual child controls.

    In my case I had a TableLayoutPanel with lots of cells of controls inside.

    I solved the flickering that was appearing during scrolling & painting of that TableLayoutPanel by deriving it and overriding the CreateParms property as depicted.

    Thanks a lot for the hint,

     

     

     

    Wednesday, July 30, 2008 3:22 PM
  •  

    Hello again,

    unfortunately I've hit the wall, WS_EX_COMPOSITED resolves the flickering problem, this is TRUE

    BUT

    it brings a CPU undesirable permanent load around 50% in my case.

    After investigation I found that the OnPaint event handler of the container having the WS_EX_COMPOSITED style is getting called indefinitely !!

    It seems several ones had this problem but no solution on the net yet ??

    Experts help !

    Regards,

    Monday, August 04, 2008 3:36 PM
  • It is like magic. I like it, thanks.

     

    Tuesday, October 28, 2008 6:04 PM
  • I can't believe this worked, I have been dealing with flicker problems for YEARS.  Completely solved my problem, and CPU usage was not abnormal for me.
    Saturday, January 10, 2009 6:00 AM
  • Hi

    i had the same exact problem with a user control with many buttons and text boxes and backgroundimage property set to some random image with resolution around 1200x900. Then i tried the proposed solution and it worked just fine :) I was happy but then i put the user control in a form-parent and called some modal dialog and guess what, when i tried to move the dialog around it was too hard and slow.... :)
    so we are in a dead end, i tried to find some other solution but most of the proposed solution is by setting styles which is not helpful. I just can't believe that there is no solution for this. Its so normal situation...I hope someone have a clue for this...

    Thank you
    Thursday, January 22, 2009 2:17 PM
  • Thank you very much! This helped me so much!

    I am creating a replacement file explorer wherein each file/folder is represented by a seperate user control (FolderViewerItem) and they are added to a FolderViewer class (Which just inherits the FlowLayoutPanel class and adds some extra functionality). Whenever I scrolled the FolderViewer the files/folders would flicker like crazy - especially when viewing the Program Files directory! This solved it 100%!
    Monday, March 30, 2009 6:00 PM
  •  Protected Overrides ReadOnly Property CreateParams() As CreateParams
        Get
          Dim cp As CreateParams = MyBase.CreateParams
          cp.ExStyle = cp.ExStyle Or &H2000000
          Return cp
        End Get
      End Property 'CreateParams
    

    Thanks a lot !
    I am using a graphics path with hundreds of Graphics elements that is been redrawn. This little magic code did the thing, no flicker at all !

    Thank you !

    Tuesday, May 12, 2009 12:33 PM
  •     protected override CreateParams CreateParams {
          get {
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x02000000;
            return cp;
          }
        }
      }
    }
    Thanks for the tip. Used it in a panel with many(100's) user controls being redrawn and the expected flickering behavior was solved. Though, if a new form hovers above this panel, the background does not seem to re-paint quick enough leaving an annoying trail to displease my eyes! (This is not observed over a normal panel)

    Thank You!
    Questor
    Wednesday, May 13, 2009 4:16 PM
  • I have a TreeView in a TabPage of this TabControl, and it flickers a lot when resizing the window (which doesn't happen if it's not in a TabControl). The TabControl itself also flickers a little on resize.

    Your second solution solves these two issues, but introduces a new one: my custom double-buffered Panels are all messed up now. More precisely, the stuff I draw on them is buggy, flickering, etc... It seems like the Panels are invalidated too often, they the stuff drawn on them disappears too quickly while it should remain on screen. Also, some parts of the Panels are not drawn (as if only painting a sub-rectangle of the Panel, the size of which seems random, as it varies each time I try).

    Any idea how to fix this? Is there anyway I can enable the overridden CreateParams behavior for all controls except certain ones?
    Sunday, June 21, 2009 4:46 PM
  • I thought "Createparams"-solution would be my solution for flickering problem and it works fine on VISTA-machine, when I tried it out on a XP-machine the graphic was redrawn all the time and it was impossible to see what was to be drawn.
    I also tried "Suspendlayout" and "Doublebuffering" but that doesn´t affect the flickering at all.

    Anybody had same problems ?
    Wednesday, July 22, 2009 10:25 AM
  • I thought "Createparams"-solution would be my solution for flickering problem and it works fine on VISTA-machine, when I tried it out on a XP-machine the graphic was redrawn all the time and it was impossible to see what was to be drawn.
    I also tried "Suspendlayout" and "Doublebuffering" but that doesn´t affect the flickering at all.

    Anybody had same problems ?


    Did you read the entire thread? 
    I believe that your issues were discussed to some degree.  Some warnings, do's and don'ts were posted.

    Mark the best replies as answers. "Fooling computers since 1971."
    Wednesday, July 22, 2009 1:30 PM


  • Did you read the entire thread? 
    I believe that your issues were discussed to some degree.  Some warnings, do's and don'ts were posted.

    Mark the best replies as answers. "Fooling computers since 1971."

    Sorry but I have read the whole thread several times but I can´t figure out what post you mean or what could be a suitable solution for the problem.
    Tuesday, July 28, 2009 8:42 AM
  • Start a new thread.  Posting a link to this one might be helpful.  Posting a code sample would be good, too.
    Mark the best replies as answers. "Fooling computers since 1971."
    Tuesday, July 28, 2009 12:38 PM
  • Your solution works very well in our project, though we are facing an issue. Our form has a media player control in it. Everything works fine in Windows 2008 server - but in a Windows XP [SP2/SP3] & Vista, the media control player displays a black rectangle - the media is playing [one can hear the audio].  A slightly strange behavior is displayed. On moving or resizing the window, the media control player displays starts working - any action like forward, rewind, pause, stop, play makes the media control player displays a black rectangle!!!!.

    Is there a fix to this issue?

    Thanks

    NR
    Wednesday, August 19, 2009 8:05 PM
  • That was explicitly noted in the OP, this trick won't work for layered windows.  You probably didn't see the problem in W2008 because Aero was turned on.

    Hans Passant.
    Wednesday, August 19, 2009 8:23 PM
    Moderator
  • Does this mean that there is no fix to this problem under Windows XP/Vista?

    Setting the WS_EX_COMPOSITED property will take care of the flicker but will mess up layered windows controls such as media player?

    Thanks

    NR
    Wednesday, August 19, 2009 8:36 PM
  • WS_EX_COMPOSITED fixes the flicker but in some cases it will make the CPU up to 50%.  I am using a MDI application and it is very frustrating.  I am shocked that Microsoft has not addresses or fixed this issue.
    Thursday, August 27, 2009 8:45 PM
  • adding the WS_EX_LAYERED style helped

    protected

     

    override CreateParams CreateParams

    {

     

    get

    {

     

    CreateParams cp = base.CreateParams;

    cp.ExStyle |= 0x02000000;

    //WS_EX_COMPOSITED. Prevents flickering.

    cp.ExStyle |= 0x00080000; //WS_EX_LAYERED. Transparency key

     

    return cp;

    }

    }

    Wednesday, March 10, 2010 6:30 PM
  • Thank you very much for your nice solution to avoid flickering.
    Monday, March 15, 2010 3:09 PM
  • Hi folks!

    I have a form with about 100 components in some panels.

    I try to add the above CreateParams property and it's work fine, with only a little problem...

    The panels are separated by splitters (System.Windows.Forms.Splitter).

    Without the CreateParam when user moves splitters all works as expected (the cursor changes and a gray line is displayed under the cursor while moving).

    With CreateParams the cursor changes but no line is displayed.

    The splitters' events are raised (Paint, SplitterMoved, ...) but nothing is drawn...

     

    Could someone say me something useful?

    I use c# with VS2008 on a Vista Business.

     

    Thanks in advice and sorry for my bad english...

     

    Luca

     

     

    Thursday, April 08, 2010 1:43 PM
  • Works very well for me, FLICKER-FREEE. CPU usage raise to 40% while the form loading and back to nomal.

     

    Wednesday, July 28, 2010 7:30 AM
  • works Great!!!Thanks

    Monday, August 16, 2010 5:47 PM
  • your solution is working perfectly..

    but in my form i have some third party controls like Infragistics UltraTab control ...that controls are not paining 

    after i use the createparams code..its showing a black strip ..i am guessing its bcoz  painting not happening for the third party control after that

    any ideas about solving this issue ?

    Wednesday, September 22, 2010 9:59 AM
  • Setting the ExStyle to WS_CLIPCHILDREN is effective in eliminating flicker, however it introduces two new problems for TreeView controls (which cannot use double-buffering: http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.doublebuffered(v=VS.80).aspx).

    1. If you are using any of the ImageList functions for drag-and-drop (i.e. ImageList_BeginDrag), which I am, the dragged image is no longer visible.  I tried clearing the WS_CLIPCHLDREN style in the OnDragOver event by calling SetWindowLong, and then redrawing the image with ImageList_DragShowNolock(true), but this does not make the drag image visible.  I'd really like to find a fix for this.

    2. If the form has a StatusStrip control at the bottom, as mine does, it is either covered up or frozen in position during vertical resize.  When resize completes, the form is redrawn correctly.  I can live with this, but prefer a solution.

    3. Icons being drawn just to the left of ImageIndex in OnDrawNode cease to be visible (cannot live without the icons).

    Is there a way to reduce flicker without these side-effects of using WS_CLIPCHILDREN ?

     


    Tim Mackey
    Monday, January 31, 2011 12:27 AM
  •  
        protected override CreateParams CreateParams {
          get {
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x02000000;
            return cp;
          }
        }
      
    That one was great and I just logged first time to thank for this.
    Monday, May 09, 2011 5:10 PM
  • THANK YOU VERY MUCH.

    it solved my problem


    Tuesday, May 24, 2011 4:45 AM
  • Dear Ajishapj, 

    There was such a problem with Infragistics UltraToolbarsManager and that was even worse. I've simply sent a sample project as a support request and they've fixed this issue at 8.2.2204 service pack. In this case you should also send your complains about UltraTabControl. Eventually Infragistics will fix this issue.  


    Issue "19004: Painting issue when overriding form’s CreateParams property" has been addressed in service release versions 8.2.20082.2198 CLR 2.0 ... 
    Tuesday, June 14, 2011 2:13 PM
  • The unpainted area's on load were very bothersome.  Setting doublebuffered on form when dropping back to design stopped showing all controls until a full rebuild it again? Wierd.

    Well after some thought the following simple solution worked for me and thought I'd pass it along;

    - The problem seems that when the control is set to visible it shows on the form while loading. I have Multiple tab controls and grids loading in tabcontrol1 so it shows a blank area on the form while loading the many other controls.  Added to all the other controls shows many stupid blank spots on the form before everthing is fully loaded. Not very elegant. My solution as an example;

    1) At design time I set tabcontrol1.visible = false.

    (note: this stops it from showing a blank area on screen while the object is being loaded with stuff)

    2) At run time at the end of Main_load I simply set tabcontrol1.visible = true

    (note: it then pops up instantly)

    Do this with all the controls in an orderly fashion and you have a blank form showing components fully populated in an orderly manner which for me is much nicer design then throwing up a bunch of blank boxes on a form loading stuff before they show up.

    It may not be a total answer but it's very simple to implement,
      I might next try setting double buffered on the form just before publishing to see how that works.

    Hope this helps.

     

    Thursday, August 25, 2011 9:25 AM
  • Hi Friends,

     

    The CreateParams property is not working in WinXp for me.

    Can anybody help me please....

     

    regards,

    Harish

    Friday, September 23, 2011 4:27 AM
  • Hi!

     

    For me too in XP CreateParams doesn't work. I have problems in W7 also if I disable aero. All controls with trasparent background (usually panels) appears with a black background.

     

    I make a "shortcut". Suppose I have a form with a tab control with 5 or 6 tabs, each tab witn a lot of controls

    1) at design mode all heavy controls (tabs, gropu box, containers)  have visible=false.

    2) each tab has a panel inside who contains controls

    3) in Frmxxx_Show method i turn visible only the tab control, the panel inside the first tan and the tabs header. The panel inside the other tabs remains visible=false.

    4) on TabChanging, I make the panel  inside the clicked tab visible = true.

     

    Using this tecnique I display (showing the form) only what the user can see when he opens the form. When the user change what he wants to see (tab) I display/paint/show what he wants.

    This increase speed and seems to be a good solution because:

    a) Painting hide objects seems to be more efficent

    b) First time (usually the only time when users say "It's slow!") I paint only visilble objects

    c) Why I must do hard work for what is not displayed? I do it when you ask me that!  ;-)

     

    Bye!

     

    LDM

     

     


    • Edited by LDM_ Friday, September 23, 2011 6:05 AM
    Friday, September 23, 2011 6:04 AM
  • Thanks man ,
    I was using Double buffer but it was of no use .
    Hide the form while loading is the best solution .

     

    Thursday, November 03, 2011 8:23 PM
  • We have a problem in a 3rd party application, where the screen flickers every time you add, delete or modify a record in the grid (when you save).  It seems to be flickering between 2 different lists of records in the grid, your current filtered list and all records in the table OR two different sort orders.  And it gets progressively worse as you get more & more records in the table.  Currently it flickers for over 60 secs with every save with 250 records in the table.

    The software vendor says it is a problem in one of the 3rd party dll's they used (an Infragistics dll I suspect) and we need to spend over $100,000 again (plus 1000's of internal man hours) to upgrade their current version (our version is only 18 months old).

    I am a novice programmer, do you think our problem is related to this thread?  What solution would you recommend?

    p.s. we have similar problems on other screens, they only flicker a few times but they still hang for 60 secs doing the save.  This would be a better situation (at least the user wouldn't see it) but not ideal.  Their new version saves in a couple secs.

    Any suggestions would be greatly appreciated, thanks.

    Friday, January 13, 2012 5:59 PM
  • Hi! Have you tried to suspend event while saving data? Like this: yourUltraGrid.SuspendRowSynchronization(); try { .. .. .. your code to save data .. .. .. } catch (Exception ex) { throw ex; } finally { yourUltraGrid.ResumeRowSynchronization(); } Bye! LDM
    Tuesday, January 17, 2012 2:56 PM
  • Thank you so much!

    I've been struggling with #2 for some weeks now, but this fixed everything! :)

    Wednesday, February 01, 2012 1:31 PM
  • Works for me on XP. Thanks!

    B. Clay Shannon

    Monday, May 07, 2012 10:54 PM
  • I'm tried to use your solution, but now my application isn't working at all. Window is flickering and I can't press any button on it. CPU loading is 50% when my program is running.

    I'm using .NET 4.0, DockPanelSuite and WinForms VirtualMode OwnerDraw ListView in my program. Without your code program works, but ListView is flickering.

    Wednesday, August 22, 2012 9:38 AM
  • Yea..this done the trick..Thank you very much for the post..!
    Monday, December 31, 2012 12:10 PM