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

前端 未结 8 1732
悲哀的现实
悲哀的现实 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:17

    This worked for me.

    http://www.syncfusion.com/faq/windowsforms/search/558.aspx

    Basically it involves deriving from the desired control and setting the following styles.

    SetStyle(ControlStyles.UserPaint, true);
    SetStyle(ControlStyles.AllPaintingInWmPaint, true); 
    SetStyle(ControlStyles.DoubleBuffer, true); 
    
    0 讨论(0)
  • 2021-01-05 11:25

    Sounds like you want double-buffering:

    http://www.codeproject.com/KB/graphics/DoubleBuffering.aspx

    Although this is mainly used for individual controls, you can implement this in your Windows Forms control or Form.

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

    You may also try this, its work.

    public static void DoubleBuffered(Control formControl, bool setting)
    {
        Type conType = formControl.GetType();
        PropertyInfo pi = conType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
        pi.SetValue(formControl, setting, null);
    }
    
    0 讨论(0)
  • 2021-01-05 11:29

    Unfortunatly, I think that thins might just be a by-product of the .net framework. I am experiencing similar flickering albeit with custom controls. Many of the reference material I have read indicates this, alongside the fact the the double buffering method failed to remove any flickering for me.

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

    Rather than adding the rows of the data grid one at a time, use the DataGridView.Rows.AddRange method to add all the rows at once. That should only update the display once. There's also a DataGridView.Columns.AddRange to do the same for the columns.

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

    People seem to forget a simple fix for this:

    Object.Visible = false;
    
    //do update work
    
    Object.Visible = true;
    

    I know it seems weird, but that works. When the object is not visible, it won't redraw itself. You still, however, need to do the begin and end update.

    0 讨论(0)
提交回复
热议问题