如何在表单上加倍缓冲 .NET 控件? [英] How to double buffer .NET controls on a form?

查看:24
本文介绍了如何在表单上加倍缓冲 .NET 控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置受闪烁影响的窗体上控件的受保护 DoubleBuffered 属性?

How can I set the protected DoubleBuffered property of the controls on a form that are suffering from flicker?

推荐答案

这是一个更通用的 Dummy 的解决方案.

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

We can use reflection to get at the protected DoubleBuffered property, and then it can be set to true.

注意:您应该支付开发者税 而不是 如果用户在终端中运行,则使用双缓冲服务会话(例如远程桌面)如果此人在远程桌面上运行,则此辅助方法不会打开双缓冲.

Note: You should pay your developer taxes and not use double-buffering if the user is running in a terminal services session (e.g. Remote Desktop) This helper method will not turn on double buffering if the person is running in remote desktop.

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); 
}

这篇关于如何在表单上加倍缓冲 .NET 控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆