none
Flicker-free painting RRS feed

  • 質問

  • 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.
    2007年8月23日 12:11
    モデレータ

すべての返信

  • Under the .NET framework 2.0 you can simply use

    class Form1 : Form {
      Form1(){
       this.doublebuffered = true;
      }
    }
    2007年8月28日 6:02
  •  

    yes thats true, no need to double buffer PictureBox as its already double bufferd (for the OnPaint)!
    2007年8月28日 15:17
  • 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.
    2007年8月28日 21:35
    モデレータ
  • 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

     

    2007年8月31日 22:42
  • Thanks.
    2007年8月31日 22:46
    モデレータ
  • 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

     

    2007年9月2日 12:48
  • Thanks for the feedback.  Should be an improvement, still.  Are you using the Paint event?
    2007年9月2日 21:40
    モデレータ
  • 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).
    • 回答の候補に設定 Bryce Graff 2016年12月19日 19:22
    2007年9月5日 7:02
  • 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. 

    2007年9月5日 20:42
  • 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.
    2007年9月6日 0:25
    モデレータ
  • 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)

    2007年9月6日 13:31
  • Wow! you rock!

     

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

     

    2007年9月6日 15:25
  • 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


    2007年9月17日 13:02
  •  

    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.

    2007年9月17日 16:27
  • 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

    2007年9月19日 12:43
  • 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

    2007年10月5日 21:51
  • 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()

    {

    }

    }

    2007年10月10日 10:01
  • I've been trying to fix the problem described in #2 for years. This works brilliantly. Thank you!!!!

    2007年10月14日 21:26
  • 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

    2007年10月29日 9:31
  • 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.

     

     

     

    2007年10月29日 16:45
  •  

    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

    2007年11月2日 5:56
  • 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


    2007年11月2日 18:58
  • 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. 

    2007年11月21日 19:01
  • 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.

    2007年11月26日 19:04
  • Deleted
    2007年12月10日 23:15
  • 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!
    2008年1月18日 15:54
  • Thanks

    very valuable post
    2008年3月13日 15:24
  • 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

    2008年3月20日 21:20
  • Great topic, thanks allot.
    2008年4月22日 5:08
  • 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)
    2008年5月7日 6:49
  • 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

    2008年5月29日 1:29
  • 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"?
    2008年5月29日 16:06
  • 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

    2008年6月10日 9:57
  • 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...?

    2008年6月16日 5:53
  • the Style can only use on winxp,not support win2k

     

    2008年7月29日 14:55
  • 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,

     

     

     

    2008年7月30日 15:22
  •  

    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,

    2008年8月4日 15:36
  • It is like magic. I like it, thanks.

     

    2008年10月28日 18:04
  • 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.
    2009年1月10日 6:00
  • 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
    2009年1月22日 14:17
  • 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%!
    2009年3月30日 18:00
  •  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 !

    2009年5月12日 12:33
  •     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
    2009年5月13日 16:16
  • 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?
    2009年6月21日 16:46
  • 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 ?
    2009年7月22日 10:25
  • 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."
    2009年7月22日 13:30


  • 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.
    2009年7月28日 8:42
  • 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."
    2009年7月28日 12:38
  • 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
    2009年8月19日 20:05
  • 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.
    2009年8月19日 20:23
    モデレータ
  • 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
    2009年8月19日 20:36
  • 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.
    2009年8月27日 20:45
  • 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;

    }

    }

    2010年3月10日 18:30
  • Thank you very much for your nice solution to avoid flickering.
    2010年3月15日 15:09
  • 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

     

     

    2010年4月8日 13:43
  • Works very well for me, FLICKER-FREEE. CPU usage raise to 40% while the form loading and back to nomal.

     

    2010年7月28日 7:30
  • works Great!!!Thanks

    2010年8月16日 17:47
  • 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 ?

    2010年9月22日 9:59
  • 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
    2011年1月31日 0:27
  •  
        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.
    2011年5月9日 17:10
  • THANK YOU VERY MUCH.

    it solved my problem


    2011年5月24日 4:45
  • 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 ... 
    2011年6月14日 14:13
  • 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.

     

    2011年8月25日 9:25
  • Hi Friends,

     

    The CreateParams property is not working in WinXp for me.

    Can anybody help me please....

     

    regards,

    Harish

    2011年9月23日 4:27
  • 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

     

     


    • 編集済み LDM_ 2011年9月23日 6:05
    2011年9月23日 6:04
  • Thanks man ,
    I was using Double buffer but it was of no use .
    Hide the form while loading is the best solution .

     

    2011年11月3日 20:23
  • 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.

    2012年1月13日 17:59
  • 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
    2012年1月17日 14:56
  • Thank you so much!

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

    2012年2月1日 13:31
  • Works for me on XP. Thanks!

    B. Clay Shannon

    2012年5月7日 22:54
  • 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.

    2012年8月22日 9:38
  • Yea..this done the trick..Thank you very much for the post..!
    2012年12月31日 12:10
  • Yea..this done the trick..Thank you very much for the post..!

    This does't work anymore with Windows 10 Creator Release. Kindly advise a fix on this. 

    2017年4月18日 9:41
  • Thanks - technique #2 also works if you have a single control that you are doing excessive drawing on.
    2019年4月3日 4:23