2025-05-28 17:13:49

1、直接写一个扩展方法,使用反射,直接上代码,将此类定义给DataGirdView或ListView所在的窗体类外面即可

public static class DoubleBufferDataGridView

{

///

/// 双缓冲,解决闪烁问题

///

///

///

public static void DoubleBufferedDataGirdView(this DataGridView dgv, bool flag)

{

Type dgvType = dgv.GetType();

PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);

pi.SetValue(dgv, flag, null);

}

}

public static class DoubleBufferListView

{

///

/// 双缓冲,解决闪烁问题

///

///

///

public static void DoubleBufferedListView(this ListView lv, bool flag)

{

Type lvType = lv.GetType();

PropertyInfo pi = lvType.GetProperty("DoubleBuffered",

BindingFlags.Instance | BindingFlags.NonPublic);

pi.SetValue(lv, flag, null);

}

}

2、调用方法

public Form1()

{

InitializeComponent();

DataGridView1.DoubleBufferedDataGirdView(true);

}

Copyright © 2088 英式橄榄球世界杯_世界杯女篮 - tylpr.com All Rights Reserved.
友情链接