Flickering during updates to Controls in WinForms (e.g. DataGridView)

前端 未结 8 1733
悲哀的现实
悲哀的现实 2021-01-05 10:43

In my application I have a DataGridView control that displays data for the selected object. When I select a different object (in a combobox above), I need to update the grid

相关标签:
8条回答
  • 2021-01-05 11:34

    Double buffering won't help here since that only double buffers paint operations, the flickering the OP is seeing is the result of multiple paint operations:

    • Clear control contents -> repaint
    • Clear columns -> repaint
    • Populate new columns -> repaint
    • Add rows -> repaint

    so that's four repaints to update the control, hence the flicker. Unfortunately, not all the standard controls have the BeginUpdate/EndUpdate which would remove all the repaint calls until the EndUpdate is called. Here's what you can do:

    1. Have a different control for each data set and Show/Hide the controls,
    2. Remove the control from its parent, update and then add the control again,
    3. Write your own control.

    Options 1 and 2 would still flicker a bit.

    On the .Net GUI program I'm working on, I created a set of custom controls that eliminated all flicker.

    0 讨论(0)
  • 2021-01-05 11:41

    The .NET control supports the SuspendLayout and ResumeLayout methods. Pick the appropriate parent control (i.e. the control that hosts the controls you want to populate) and do something like the following:

    this.SuspendLayout();
    
    // Do something interesting.
    
    this.ResumeLayout();
    
    0 讨论(0)
提交回复
热议问题