Skip to content

Commit d1ead18

Browse files
authored
2520-V100-add-double-buffered-extension (#2521)
- Add the extension - A little housekeeping on Extensions.cs - No changelog, for internal use only.
1 parent f648e3f commit d1ead18

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

Source/Krypton Components/Krypton.Toolkit/General/Extensions.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Krypton.Toolkit;
1111

1212
internal static class Extensions
1313
{
14+
#region Control.InDesignMode & Component.InDesignMode
1415
/// <summary>
1516
/// Returns if the control is in desigmode.
1617
/// </summary>
@@ -30,5 +31,50 @@ internal static bool InDesignMode(this Component component)
3031
{
3132
return component.Site?.DesignMode ?? false;
3233
}
34+
#endregion
35+
36+
#region Control.DoubleBuffered
37+
/// <summary>
38+
/// Enable or disable double buffering on the given control.<br/>
39+
/// Note: Some classes derived from Control expose their own DoubleBuffered property.
40+
/// </summary>
41+
/// <param name="control">The instance to operate on.</param>
42+
/// <param name="enableDoubleBuffering">Enable or disable double buffering.</param>
43+
/// <exception cref="NullReferenceException">When the property was not found.</exception>
44+
internal static void SetDoubleBuffered(this Control control, bool enableDoubleBuffering)
45+
{
46+
PropertyInfo? propertyInfo = typeof(Control).GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
47+
if (propertyInfo is not null)
48+
{
49+
propertyInfo.SetValue(control, enableDoubleBuffering);
50+
}
51+
else
52+
{
53+
throw new NullReferenceException(nameof(propertyInfo));
54+
}
55+
}
56+
57+
/// <summary>
58+
/// Return the state of the control's DoubleBuffered property.<br/>
59+
/// Note: Some classes derived from Control expose their own DoubleBuffered property.
60+
/// </summary>
61+
/// <param name="control">The instance to operate on.</param>
62+
/// <returns>The current state.</returns>
63+
/// <exception cref="NullReferenceException">When the property was not found.</exception>
64+
internal static bool GetDoubleBuffered(this Control control)
65+
{
66+
PropertyInfo? propertyInfo = typeof(Control).GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
67+
if (propertyInfo is not null)
68+
{
69+
return propertyInfo.GetValue(control) is bool result
70+
? result
71+
: false;
72+
}
73+
else
74+
{
75+
throw new NullReferenceException(nameof(propertyInfo));
76+
}
77+
}
78+
#endregion
3379
}
3480

0 commit comments

Comments
 (0)