小编典典

如何在窗体上加倍缓冲.NET控件?

c#

如何DoubleBuffered在出现闪烁的窗体上设置控件的保护属性?


阅读 235

收藏
2020-05-19

共1个答案

小编典典

这是Dummy解决方案的通用版本。

我们可以使用反射来获取受保护的DoubleBuffered属性,然后可以将其设置为
true

注意
如果用户在终端服务会话(例如,远程桌面)中运行,则应缴纳开发人员税,并且不使用双缓冲。如果此人在远程桌面中运行,则此帮助程序方法将不会启用双缓冲。

public static void SetDoubleBuffered(System.Windows.Forms.Control c)
{
   //Taxes: Remote Desktop Connection and painting
   //http://blogs.msdn.com/oldnewthing/archive/2006/01/03/508694.aspx
   if (System.Windows.Forms.SystemInformation.TerminalServerSession)
      return;

   System.Reflection.PropertyInfo aProp = 
         typeof(System.Windows.Forms.Control).GetProperty(
               "DoubleBuffered", 
               System.Reflection.BindingFlags.NonPublic | 
               System.Reflection.BindingFlags.Instance);

   aProp.SetValue(c, true, null); 
}
2020-05-19