Set DoubleBuffered Property [C#]
This example shows how to set protected property Control.DoubleBuffered to true. This is useful, if you want to avoid flickering of controls such as ListView (when updating) or Panel (when you draw on it).
All controls have property DoubleBuffered, but this property is protected. Usually you need to create a new class (inherited from the control) and set the protected property. This example shows a little hack. You can use reflection to access non-public methods and properties. See the example.
[C#]public static void SetDoubleBuffered(Control control) { // set instance non-public property with name "DoubleBuffered" to true typeof(Control).InvokeMember("DoubleBuffered", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, control, new object[] { true }); }
See also
- [C#] Redraw a Whole Control on Resize – ensure a resized control is redrawn properly
- [C#] Topmost Form at Application Level – don't overlap other application forms
- [C#] InputBox – simple static method to show InputBox in C#
- [C#] InputBox With Value Validation – improved InputBox class
- [C#] Separator Line on Form – simulate a bevel line on form
- [C#] Hourglass Wait Cursor – how to change mouse cursor to hourglass
- Control.DoubleBuffered – MSDN – protected property to redraw control using double-buffer to prevent flickers
- Type.InvokeMember – MSDN – invokes a specific member of the current Type