Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Last revisionBoth sides next revision
fuss:csharp [2019/08/22 07:32] – [Recursive] officefuss:csharp [2021/05/08 03:22] – [Iterative] office
Line 1786: Line 1786:
 </code> </code>
  
 +====== Enable Double Buffering for Controls ======
 +
 +Some window forms controls do not expose the double buffering property such that the following static extension method will attempt to enable double buffering and return true on success or false otherwise.
 +
 +<code csharp>
 +        /// <summary>
 +        /// Enable double buffering for an arbitrary control.
 +        /// </summary>
 +        /// <param name="control">the control to enable double buffering for</param>
 +        /// <returns>true on success</returns>
 +        /// <remarks>Do not enable double buffering on RDP: https://devblogs.microsoft.com/oldnewthing/20060103-12/?p=32793</remarks>
 +        public static bool SetDoubleBuffered(this Control control)
 +        {
 +            if (SystemInformation.TerminalServerSession)
 +            {
 +                return false;
 +            }
 +
 +            var dgvType = control.GetType();
 +            var pi = dgvType.GetProperty("DoubleBuffered",
 +                BindingFlags.Instance | BindingFlags.NonPublic);
 +            if (pi == null)
 +            {
 +                return false;
 +            }
 +
 +            pi.SetValue(control, true, null);
 +
 +            return true;
 +        }
 +</code>
 +
 +Enabling double buffering can be particularly beneficial for ''DataGridView'' controls that seem to speed up noticeably.
  

fuss/csharp.txt · Last modified: 2022/04/19 08:28 by 127.0.0.1

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.