@@ -11,6 +11,7 @@ namespace Krypton.Toolkit;
11
11
12
12
internal static class Extensions
13
13
{
14
+ #region Control.InDesignMode & Component.InDesignMode
14
15
/// <summary>
15
16
/// Returns if the control is in desigmode.
16
17
/// </summary>
@@ -30,5 +31,50 @@ internal static bool InDesignMode(this Component component)
30
31
{
31
32
return component . Site ? . DesignMode ?? false ;
32
33
}
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
33
79
}
34
80
0 commit comments