@@ -11,6 +11,7 @@ public sealed partial class ColorPicker : UserControl
11
11
12
12
private Color color ;
13
13
private bool hexadecimal ;
14
+ private bool ignoreOnChanged = false ;
14
15
15
16
public ColorPicker ( )
16
17
{
@@ -24,7 +25,15 @@ public Color Value
24
25
get { return color ; }
25
26
set
26
27
{
28
+ if ( color == value )
29
+ return ;
27
30
color = value ;
31
+ ignoreOnChanged = true ;
32
+ nslAlpha . Value = color . A ;
33
+ nslRed . Value = color . R ;
34
+ nslGreen . Value = color . G ;
35
+ nslBlue . Value = color . B ;
36
+ ignoreOnChanged = false ;
28
37
UpdateColor ( ) ;
29
38
}
30
39
}
@@ -60,9 +69,17 @@ protected override void OnLoad(EventArgs e)
60
69
chkHexadecimal . CheckedChanged += ( obj , args ) => Hexadecimal = chkHexadecimal . Checked ;
61
70
UpdateColor ( ) ;
62
71
}
63
-
72
+
73
+ private void OnColorChanged ( )
74
+ {
75
+ if ( ! ignoreOnChanged && ColorChanged != null )
76
+ ColorChanged ( this , Value ) ;
77
+ }
78
+
64
79
private void UpdateColor ( )
65
80
{
81
+ if ( ignoreOnChanged )
82
+ return ;
66
83
var newColor = Color . FromArgb (
67
84
Convert . ToInt32 ( nslAlpha . Value ) ,
68
85
Convert . ToInt32 ( nslRed . Value ) ,
@@ -71,8 +88,7 @@ private void UpdateColor()
71
88
if ( pbColor . ColorSample == newColor )
72
89
return ;
73
90
pbColor . ColorSample = newColor ;
74
- if ( ColorChanged != null )
75
- ColorChanged ( this , Value ) ;
91
+ OnColorChanged ( ) ;
76
92
}
77
93
}
78
94
}
0 commit comments