1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2005 Novell, Inc. (http://www.novell.com)
23 // Alexander Olk xenomorph2@onlinehome.de
28 using System.ComponentModel;
30 using System.Globalization;
31 using System.Resources;
33 namespace System.Windows.Forms
35 [DefaultProperty( "Color" )]
36 public class ColorDialog : CommonDialog
38 #region Local Variables
39 private ColorDialogPanel colorDialogPanel = null;
40 private bool allowFullOpen = true;
41 private bool anyColor = false;
42 private Color color = Color.Black;
43 private int[] customColors = null;
44 private bool fullOpen = false;
45 private bool showHelp = false;
46 private bool solidColorOnly = false;
47 #endregion // Local Variables
49 #region Public Constructors
50 public ColorDialog( ) : base()
54 form.Size = new Size( 221, 332 ); // 300
56 #endregion // Public Constructors
58 #region Public Instance Properties
73 public virtual bool AllowFullOpen
82 allowFullOpen = value;
86 // Currently AnyColor internally is always true
87 // Does really anybody still use 256 or less colors ???
88 // Naw, cairo only supports 24bit anyway - pdb
90 public virtual bool AnyColor
103 [DefaultValue(false)]
104 public virtual bool FullOpen
118 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
119 public int[] CustomColors
128 customColors = value;
132 [DefaultValue(false)]
133 public virtual bool ShowHelp
146 [DefaultValue(false)]
147 public virtual bool SolidColorOnly
151 return solidColorOnly;
156 solidColorOnly = value;
159 #endregion // Public Instance Properties
161 #region Public Instance Methods
162 public override void Reset( )
164 allowFullOpen = true;
170 solidColorOnly = false;
173 public override string ToString( )
175 return base.ToString( ) + ", Color: " + Color.ToString( );
177 #endregion // Public Instance Methods
179 #region Protected Instance Properties
180 protected virtual IntPtr Instance
185 return (IntPtr)GetHashCode( );
189 protected virtual int Options
197 #endregion // Protected Instance Properties
199 #region Protected Instance Methods
200 protected override bool RunDialog( IntPtr hwndOwner )
202 colorDialogPanel = new ColorDialogPanel (this);
203 form.Controls.Add( colorDialogPanel );
205 if ( customColors != null )
206 colorDialogPanel.BaseColorControl.SetCustomColors( );
210 #endregion // Protected Instance Methods
212 #region Private Classes
213 internal class ColorDialogPanel : Panel
215 #region Local Variables
216 private Panel selectedColorPanel;
217 private BaseColorControl baseColorControl;
218 private ColorMatrixControl colorMatrixControl;
219 private BrightnessControl brightnessControl;
220 private TriangleControl triangleControl;
222 private Button okButton;
223 private Button cancelButton;
224 private Button helpButton;
225 private Button addColoursButton;
226 private Button defineColoursButton;
228 private TextBox hueTextBox;
229 private TextBox satTextBox;
230 private TextBox briTextBox;
231 private TextBox redTextBox;
232 private TextBox greenTextBox;
233 private TextBox blueTextBox;
235 private Label briLabel;
236 private Label satLabel;
237 private Label hueLabel;
238 private Label colorBaseLabel;
239 private Label greenLabel;
240 private Label blueLabel;
241 private Label redLabel;
243 private ColorDialog colorDialog;
244 #endregion // Local Variables
246 internal ColorDialogPanel( ColorDialog colorDialog )
248 this.colorDialog = colorDialog;
250 satTextBox = new TextBox( );
251 briTextBox = new TextBox( );
252 blueTextBox = new TextBox( );
253 greenTextBox = new TextBox( );
254 redTextBox = new TextBox( );
255 hueTextBox = new TextBox( );
257 redLabel = new Label( );
258 blueLabel = new Label( );
259 greenLabel = new Label( );
260 colorBaseLabel = new Label( );
261 hueLabel = new Label( );
262 satLabel = new Label( );
263 briLabel = new Label( );
265 okButton = new Button( );
266 cancelButton = new Button( );
267 if (colorDialog.ShowHelp)
268 helpButton = new Button( );
269 defineColoursButton = new Button( );
270 addColoursButton = new Button( );
272 baseColorControl = new BaseColorControl( this );
273 colorMatrixControl = new ColorMatrixControl( this );
274 brightnessControl = new BrightnessControl( this );
275 triangleControl = new TriangleControl( this );
277 selectedColorPanel = new Panel( );
282 hueTextBox.Location = new Point( 324, 203 );
283 hueTextBox.Size = new Size( 27, 21 );
284 hueTextBox.TabIndex = 11;
285 hueTextBox.TextAlign = HorizontalAlignment.Right;
286 hueTextBox.MaxLength = 3;
288 satTextBox.Location = new Point( 324, 225 );
289 satTextBox.Size = new Size( 27, 21 );
290 satTextBox.TabIndex = 15;
291 satTextBox.TextAlign = HorizontalAlignment.Right;
292 satTextBox.MaxLength = 3;
294 greenTextBox.Location = new Point( 404, 225 );
295 greenTextBox.Size = new Size( 27, 21 );
296 greenTextBox.TabIndex = 18;
297 greenTextBox.TextAlign = HorizontalAlignment.Right;
298 greenTextBox.MaxLength = 3;
300 briTextBox.Location = new Point( 324, 247 );
301 briTextBox.Size = new Size( 27, 21 );
302 briTextBox.TabIndex = 16;
303 briTextBox.TextAlign = HorizontalAlignment.Right;
304 briTextBox.MaxLength = 3;
306 blueTextBox.Location = new Point( 404, 247 );
307 blueTextBox.Size = new Size( 27, 21 );
308 blueTextBox.TabIndex = 19;
309 blueTextBox.TextAlign = HorizontalAlignment.Right;
310 blueTextBox.MaxLength = 3;
312 redTextBox.Location = new Point( 404, 203 );
313 redTextBox.Size = new Size( 27, 21 );
314 redTextBox.TabIndex = 17;
315 redTextBox.TextAlign = HorizontalAlignment.Right;
316 redTextBox.MaxLength = 3;
319 redLabel.FlatStyle = FlatStyle.System;
320 redLabel.Location = new Point( 361, 206 );
321 redLabel.Size = new Size( 40, 16 );
322 redLabel.TabIndex = 25;
323 redLabel.Text = Locale.GetText( "Red" ) + ":";
324 redLabel.TextAlign = ContentAlignment.MiddleRight;
326 blueLabel.FlatStyle = FlatStyle.System;
327 blueLabel.Location = new Point( 361, 250 );
328 blueLabel.Size = new Size( 40, 16 );
329 blueLabel.TabIndex = 26;
330 blueLabel.Text = Locale.GetText( "Blue" ) + ":";
331 blueLabel.TextAlign = ContentAlignment.MiddleRight;
333 greenLabel.FlatStyle = FlatStyle.System;
334 greenLabel.Location = new Point( 361, 228 );
335 greenLabel.Size = new Size( 40, 16 );
336 greenLabel.TabIndex = 27;
337 greenLabel.Text = Locale.GetText( "Green" ) + ":";
338 greenLabel.TextAlign = ContentAlignment.MiddleRight;
340 colorBaseLabel.Location = new Point( 228, 247 );
341 colorBaseLabel.Size = new Size( 60, 25 );
342 colorBaseLabel.TabIndex = 28;
343 colorBaseLabel.Text = Locale.GetText( "Color" );
344 colorBaseLabel.TextAlign = ContentAlignment.MiddleCenter;
346 hueLabel.FlatStyle = FlatStyle.System;
347 hueLabel.Location = new Point( 287, 206 );
348 hueLabel.Size = new Size( 36, 16 );
349 hueLabel.TabIndex = 23;
350 hueLabel.Text = Locale.GetText( "Hue" ) + ":";
351 hueLabel.TextAlign = ContentAlignment.MiddleRight;
353 satLabel.FlatStyle = FlatStyle.System;
354 satLabel.Location = new Point( 287, 228 );
355 satLabel.Size = new Size( 36, 16 );
356 satLabel.TabIndex = 22;
357 satLabel.Text = Locale.GetText( "Sat" ) + ":";
358 satLabel.TextAlign = ContentAlignment.MiddleRight;
360 briLabel.FlatStyle = FlatStyle.System;
361 briLabel.Location = new Point( 287, 250 );
362 briLabel.Size = new Size( 36, 16 );
363 briLabel.TabIndex = 24;
364 briLabel.Text = Locale.GetText( "Bri" ) + ":";
365 briLabel.TextAlign = ContentAlignment.MiddleRight;
367 // defineColoursButton
368 defineColoursButton.FlatStyle = FlatStyle.System;
369 defineColoursButton.Location = new Point( 5, 244 );
370 defineColoursButton.Size = new Size( 210, 22 );
371 defineColoursButton.TabIndex = 6;
372 defineColoursButton.Text = Locale.GetText( "Define Colours >>" );
374 okButton.FlatStyle = FlatStyle.System;
375 okButton.Location = new Point( 5, 271 );
376 okButton.Size = new Size( 66, 22 );
377 okButton.TabIndex = 0;
378 okButton.Text = Locale.GetText( "OK" );
380 cancelButton.FlatStyle = FlatStyle.System;
381 cancelButton.Location = new Point( 78, 271 );
382 cancelButton.Size = new Size( 66, 22 );
383 cancelButton.TabIndex = 1;
384 cancelButton.Text = Locale.GetText( "Cancel" );
386 if (colorDialog.ShowHelp) {
387 helpButton.FlatStyle = FlatStyle.System;
388 helpButton.Location = new Point( 149, 271 );
389 helpButton.Size = new Size( 66, 22 );
390 helpButton.TabIndex = 5;
391 helpButton.Text = Locale.GetText ( "Help" );
395 addColoursButton.FlatStyle = FlatStyle.System;
396 addColoursButton.Location = new Point( 227, 271 );
397 addColoursButton.Size = new Size( 213, 22 );
398 addColoursButton.TabIndex = 7;
399 addColoursButton.Text = Locale.GetText( "Add Colours" );
402 baseColorControl.Location = new Point( 3, 6 );
403 baseColorControl.Size = new Size( 212, 231 );
404 baseColorControl.TabIndex = 13;
405 // colorMatrixControl
406 colorMatrixControl.Location = new Point( 227, 7 );
407 colorMatrixControl.Size = new Size( 179, 190 );
408 colorMatrixControl.TabIndex = 14;
410 triangleControl.Location = new Point( 432, 0 );
411 triangleControl.Size = new Size( 16, 204 );
412 triangleControl.TabIndex = 12;
414 brightnessControl.Location = new Point( 415, 7 );
415 brightnessControl.Size = new Size( 14, 190 );
416 brightnessControl.TabIndex = 20;
418 // selectedColorPanel
419 selectedColorPanel.BackColor = SystemColors.Desktop;
420 selectedColorPanel.BorderStyle = BorderStyle.Fixed3D;
421 selectedColorPanel.Location = new Point( 227, 202 );
422 selectedColorPanel.Size = new Size( 60, 42 );
423 selectedColorPanel.TabIndex = 10;
425 ClientSize = new Size( 448, 332 ); // 300
426 Controls.Add( hueTextBox );
427 Controls.Add( satTextBox );
428 Controls.Add( briTextBox );
429 Controls.Add( redTextBox );
430 Controls.Add( greenTextBox );
431 Controls.Add( blueTextBox );
433 Controls.Add( defineColoursButton );
434 Controls.Add( okButton );
435 Controls.Add( cancelButton );
436 if (colorDialog.ShowHelp)
437 Controls.Add( helpButton );
438 Controls.Add( addColoursButton );
440 Controls.Add( baseColorControl );
441 Controls.Add( colorMatrixControl );
442 Controls.Add( brightnessControl );
443 Controls.Add( triangleControl );
445 Controls.Add( colorBaseLabel );
446 Controls.Add( greenLabel );
447 Controls.Add( blueLabel );
448 Controls.Add( redLabel );
449 Controls.Add( briLabel );
450 Controls.Add( hueLabel );
451 Controls.Add( satLabel );
453 Controls.Add( selectedColorPanel );
455 ResumeLayout( false );
457 brightnessControl.ColorToShow = selectedColorPanel.BackColor;
459 redTextBox.Text = selectedColorPanel.BackColor.R.ToString( );
460 greenTextBox.Text = selectedColorPanel.BackColor.G.ToString( );
461 blueTextBox.Text = selectedColorPanel.BackColor.B.ToString( );
463 HSB hsb = HSB.RGB2HSB( selectedColorPanel.BackColor );
464 hueTextBox.Text = hsb.hue.ToString( );
465 satTextBox.Text = hsb.sat.ToString( );
466 briTextBox.Text = hsb.bri.ToString( );
468 if ( !colorDialog.AllowFullOpen )
469 defineColoursButton.Enabled = false;
471 if ( colorDialog.FullOpen )
472 DoButtonDefineColours( );
474 defineColoursButton.Click += new EventHandler( OnClickButtonDefineColours );
475 addColoursButton.Click += new EventHandler( OnClickButtonAddColours );
476 if (colorDialog.ShowHelp)
477 helpButton.Click += new EventHandler( OnClickHelpButton );
478 cancelButton.Click += new EventHandler( OnClickCancelButton );
479 okButton.Click += new EventHandler( OnClickOkButton );
481 hueTextBox.KeyPress += new KeyPressEventHandler( OnKeyPressTextBoxes );
482 satTextBox.KeyPress += new KeyPressEventHandler( OnKeyPressTextBoxes );
483 briTextBox.KeyPress += new KeyPressEventHandler( OnKeyPressTextBoxes );
484 redTextBox.KeyPress += new KeyPressEventHandler( OnKeyPressTextBoxes );
485 greenTextBox.KeyPress += new KeyPressEventHandler( OnKeyPressTextBoxes );
486 blueTextBox.KeyPress += new KeyPressEventHandler( OnKeyPressTextBoxes );
488 SetStyle( ControlStyles.DoubleBuffer, true );
491 public Panel SelectedColorPanel
495 selectedColorPanel = value;
500 return selectedColorPanel;
504 public BrightnessControl BrightnessControl
508 brightnessControl = value;
513 return brightnessControl;
517 public TextBox HueTextBox
530 public ColorMatrixControl ColorMatrixControl
534 colorMatrixControl = value;
539 return colorMatrixControl;
543 public TriangleControl TriangleControl
547 triangleControl = value;
552 return triangleControl;
556 public TextBox RedTextBox
569 public TextBox GreenTextBox
573 greenTextBox = value;
582 public BaseColorControl BaseColorControl
586 baseColorControl = value;
591 return baseColorControl;
595 public TextBox BlueTextBox
608 public TextBox SatTextBox
621 public TextBox BriTextBox
634 public ColorDialog ColorDialog
647 void OnClickCancelButton( object sender, EventArgs e )
649 colorDialog.form.Controls.Remove( this );
650 colorDialog.form.DialogResult = DialogResult.Cancel;
653 void OnClickOkButton( object sender, EventArgs e )
655 colorDialog.form.Controls.Remove( this );
656 colorDialog.form.DialogResult = DialogResult.OK;
659 void OnClickButtonDefineColours( object sender, EventArgs e )
661 DoButtonDefineColours( );
664 private void DoButtonDefineColours( )
666 defineColoursButton.Enabled = false;
668 colorDialog.FullOpen = true;
670 colorMatrixControl.ColorToShow = baseColorControl.ColorToShow;
672 colorDialog.form.ClientSize = new Size( 448, 332 );
675 void OnClickButtonAddColours( object sender, EventArgs e )
677 baseColorControl.SetUserColor( selectedColorPanel.BackColor );
680 // FIXME: Is this correct ?
681 void OnClickHelpButton( object sender, EventArgs e )
683 colorDialog.OnHelpRequest( e );
686 // not working 100 %, S.W.F.TextBox isn't finished yet
687 void OnKeyPressTextBoxes( object sender, KeyPressEventArgs e )
689 // accept only '0', '1', ... , '9'
690 // 48 = '0', 57 = '9'
691 if ( e.KeyChar < (char)48 || e.KeyChar > (char)57 )
694 TextChangedTextBoxes( sender );
697 // not working 100 %, S.W.F.TextBox isn't finished yet
698 void TextChangedTextBoxes( object sender )
700 if ( ( (TextBox)sender ).Text.Length == 0 )
705 if ( sender == hueTextBox )
707 val = System.Convert.ToInt32( hueTextBox.Text );
712 hueTextBox.Text = val.ToString( );
718 hueTextBox.Text = val.ToString( );
721 UpdateFromHSBTextBoxes( );
723 UpdateControls( selectedColorPanel.BackColor );
726 if ( sender == satTextBox )
728 val = System.Convert.ToInt32( satTextBox.Text );
733 satTextBox.Text = val.ToString( );
739 satTextBox.Text = val.ToString( );
742 UpdateFromHSBTextBoxes( );
744 UpdateControls( selectedColorPanel.BackColor );
747 if ( sender == briTextBox )
749 val = System.Convert.ToInt32( briTextBox.Text );
754 briTextBox.Text = val.ToString( );
760 briTextBox.Text = val.ToString( );
763 UpdateFromHSBTextBoxes( );
765 UpdateControls( selectedColorPanel.BackColor );
768 if ( sender == redTextBox )
770 val = System.Convert.ToInt32( redTextBox.Text );
775 redTextBox.Text = val.ToString( );
781 redTextBox.Text = val.ToString( );
784 UpdateFromRGBTextBoxes( );
787 if ( sender == greenTextBox )
789 val = System.Convert.ToInt32( greenTextBox.Text );
794 greenTextBox.Text = val.ToString( );
800 greenTextBox.Text = val.ToString( );
803 UpdateFromRGBTextBoxes( );
806 if ( sender == blueTextBox )
808 val = System.Convert.ToInt32( blueTextBox.Text );
813 blueTextBox.Text = val.ToString( );
819 blueTextBox.Text = val.ToString( );
822 UpdateFromRGBTextBoxes( );
826 public void UpdateControls( Color color )
828 colorDialog.Color = color;
829 selectedColorPanel.BackColor = color;
830 colorMatrixControl.ColorToShow = color;
831 brightnessControl.ColorToShow = color;
832 triangleControl.ColorToShow = color;
835 public void UpdateRGBTextBoxes( Color color )
837 redTextBox.Text = color.R.ToString( );
838 greenTextBox.Text = color.G.ToString( );
839 blueTextBox.Text = color.B.ToString( );
842 public void UpdateHSBTextBoxes( Color color )
844 HSB hsb = HSB.RGB2HSB( color );
846 hueTextBox.Text = hsb.hue.ToString( );
847 satTextBox.Text = hsb.sat.ToString( );
848 briTextBox.Text = hsb.bri.ToString( );
851 public void UpdateFromHSBTextBoxes( )
853 Color col = HSB.HSB2RGB( System.Convert.ToInt32( hueTextBox.Text ),
854 System.Convert.ToInt32( satTextBox.Text ),
855 System.Convert.ToInt32( briTextBox.Text ) );
857 selectedColorPanel.BackColor = col;
858 UpdateRGBTextBoxes( col );
861 public void UpdateFromRGBTextBoxes( )
863 Color col = Color.FromArgb( System.Convert.ToInt32( redTextBox.Text ),
864 System.Convert.ToInt32( greenTextBox.Text ),
865 System.Convert.ToInt32( blueTextBox.Text ) );
867 selectedColorPanel.BackColor = col;
869 UpdateHSBTextBoxes( col );
871 UpdateFromHSBTextBoxes( );
873 UpdateControls( col );
883 public static HSB RGB2HSB( Color color )
885 HSB hsb = new HSB( );
887 hsb.hue = (int)( ( color.GetHue( ) / 360.0f ) * 241 );
888 hsb.sat = (int)( color.GetSaturation( ) * 241 );
889 hsb.bri = (int)( color.GetBrightness( ) * 240 );
891 if ( hsb.hue > 240 ) hsb.hue = 240;
892 if ( hsb.sat > 240 ) hsb.sat = 240;
893 if ( hsb.bri > 239 ) hsb.bri = 239;
898 // not using ControlPaint HBS2Color, this algo is more precise
899 public static Color HSB2RGB( int hue, int saturation, int brightness )
907 if ( saturation > 240 )
910 if ( saturation < 0 )
913 if ( brightness > 239 )
916 if ( brightness < 0 )
919 float H = hue / 240.0f;
920 float S = saturation / 240.0f;
921 float L = brightness / 239.0f;
923 float r = 0, g = 0, b = 0;
938 d2 = ( L <= 0.5f ) ? L * ( 1.0f + S ) : L + S - ( L * S );
941 float[] d3 = new float[] { H + 1.0f / 3.0f , H, H - 1.0f / 3.0f };
942 float[] rgb = new float[] { 0,0,0 };
944 for ( int i = 0; i < 3; i++ )
948 if ( d3[ i ] > 1.0f )
951 if ( 6.0f * d3[ i ] < 1.0f )
952 rgb[ i ] = d1 + ( d2 - d1 ) * d3[ i ] * 6.0f;
954 if ( 2.0f * d3[ i ] < 1.0f )
957 if ( 3.0f * d3[ i ] < 2.0f )
958 rgb[ i ] = ( d1 + ( d2 - d1 ) * ( ( 2.0f / 3.0f ) - d3[ i ] ) * 6.0f );
991 return Color.FromArgb( (int)r, (int)g, (int)b );
994 public static int Brightness( Color color )
996 return (int)( color.GetBrightness( ) * 240 );
999 public static void GetHueSaturation( Color color, out int hue, out int sat )
1001 hue = (int)( ( color.GetHue( ) / 360.0f ) * 241 );
1002 sat = (int)( color.GetSaturation( ) * 241 );
1006 // there are some small glitches, but it is still better than ControlPaint implementation
1007 public static void TestColor( Color color )
1009 Console.WriteLine( "Color: " + color );
1010 HSB hsb = HSB.RGB2HSB( color );
1011 Console.WriteLine( "RGB2HSB: " + hsb.hue + ", " + hsb.sat + ", " + hsb.bri );
1012 Console.WriteLine( "HSB2RGB: " + HSB.HSB2RGB( hsb.hue, hsb.sat, hsb.bri ) );
1013 Console.WriteLine( );
1017 internal class BaseColorControl : Control
1019 internal class SmallColorControl : Control
1021 private Color color;
1023 private bool isSelected = false;
1024 private bool hasFocus = false;
1026 public SmallColorControl( Color color )
1030 Size = new Size( 26, 23 );
1032 SetStyle( ControlStyles.DoubleBuffer, true );
1033 SetStyle( ControlStyles.AllPaintingInWmPaint, true );
1034 SetStyle( ControlStyles.UserPaint, true );
1035 SetStyle( ControlStyles.Selectable, true );
1038 public bool IsSelected
1068 protected override void OnPaint( PaintEventArgs pe )
1072 pe.Graphics.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( BackColor ), 0, 0, 26, 23 );
1074 ControlPaint.DrawBorder3D( pe.Graphics, new Rectangle( 3, 3, 20, 18 ) );
1076 pe.Graphics.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( color ),
1077 new Rectangle( 4, 4, 16, 14 ) );
1081 using ( Pen pen = new Pen( ThemeEngine.Current.ResPool.GetSolidBrush( Color.Black ) ) )
1083 pe.Graphics.DrawRectangle( pen,
1084 new Rectangle( 2, 2, 20, 18 ) );
1088 if ( hasFocus && isSelected )
1090 ControlPaint.DrawFocusRectangle(
1091 pe.Graphics, new Rectangle( 0, 0, 25, 23 )
1096 protected override void OnLostFocus( EventArgs e )
1103 base.OnLostFocus( e );
1106 protected override void OnMouseUp( MouseEventArgs e )
1115 base.OnMouseUp( e );
1119 private SmallColorControl[] smallColorControl;
1121 private SmallColorControl[] userSmallColorControl;
1123 private Label userColorLabel;
1124 private Label baseColorLabel;
1126 private bool panelSelected = false;
1128 private SmallColorControl selectedSmallColorControl;
1130 private int currentlyUsedUserSmallColorControl = 0;
1131 private int[] customColors = null;
1133 private ColorDialogPanel colorDialogPanel = null;
1135 public BaseColorControl( ColorDialogPanel colorDialogPanel )
1137 this.colorDialogPanel = colorDialogPanel;
1139 userSmallColorControl = new SmallColorControl[ 16 ];
1140 userSmallColorControl[ 0 ] = new SmallColorControl( Color.White );
1141 userSmallColorControl[ 1 ] = new SmallColorControl( Color.White );
1142 userSmallColorControl[ 2 ] = new SmallColorControl( Color.White );
1143 userSmallColorControl[ 3 ] = new SmallColorControl( Color.White );
1144 userSmallColorControl[ 4 ] = new SmallColorControl( Color.White );
1145 userSmallColorControl[ 5 ] = new SmallColorControl( Color.White );
1146 userSmallColorControl[ 6 ] = new SmallColorControl( Color.White );
1147 userSmallColorControl[ 7 ] = new SmallColorControl( Color.White );
1148 userSmallColorControl[ 8 ] = new SmallColorControl( Color.White );
1149 userSmallColorControl[ 9 ] = new SmallColorControl( Color.White );
1150 userSmallColorControl[ 10 ] = new SmallColorControl( Color.White );
1151 userSmallColorControl[ 11 ] = new SmallColorControl( Color.White );
1152 userSmallColorControl[ 12 ] = new SmallColorControl( Color.White );
1153 userSmallColorControl[ 13 ] = new SmallColorControl( Color.White );
1154 userSmallColorControl[ 14 ] = new SmallColorControl( Color.White );
1155 userSmallColorControl[ 15 ] = new SmallColorControl( Color.White );
1157 smallColorControl = new SmallColorControl[ 48 ];
1158 smallColorControl[ 0 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 255 ) ), ( (Byte)( 128 ) ), ( (Byte)( 138 ) ) ) );
1159 smallColorControl[ 1 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 128 ) ), ( (Byte)( 128 ) ), ( (Byte)( 64 ) ) ) );
1160 smallColorControl[ 2 ] = new SmallColorControl( Color.Gray );
1161 smallColorControl[ 3 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 128 ) ), ( (Byte)( 0 ) ), ( (Byte)( 255 ) ) ) );
1162 smallColorControl[ 4 ] = new SmallColorControl( Color.Silver );
1163 smallColorControl[ 5 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 64 ) ), ( (Byte)( 128 ) ), ( (Byte)( 128 ) ) ) );
1164 smallColorControl[ 6 ] = new SmallColorControl( Color.White );
1165 smallColorControl[ 7 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 64 ) ), ( (Byte)( 0 ) ), ( (Byte)( 64 ) ) ) );
1166 smallColorControl[ 8 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 255 ) ), ( (Byte)( 128 ) ), ( (Byte)( 64 ) ) ) );
1167 smallColorControl[ 9 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 128 ) ), ( (Byte)( 64 ) ), ( (Byte)( 64 ) ) ) );
1168 smallColorControl[ 10 ] = new SmallColorControl( Color.Teal );
1169 smallColorControl[ 11 ] = new SmallColorControl( Color.Lime );
1170 smallColorControl[ 12 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 128 ) ), ( (Byte)( 128 ) ), ( (Byte)( 255 ) ) ) );
1171 smallColorControl[ 13 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 0 ) ), ( (Byte)( 64 ) ), ( (Byte)( 128 ) ) ) );
1172 smallColorControl[ 14 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 255 ) ), ( (Byte)( 0 ) ), ( (Byte)( 128 ) ) ) );
1173 smallColorControl[ 15 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 128 ) ), ( (Byte)( 255 ) ), ( (Byte)( 0 ) ) ) );
1174 smallColorControl[ 16 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 0 ) ), ( (Byte)( 255 ) ), ( (Byte)( 64 ) ) ) );
1175 smallColorControl[ 17 ] = new SmallColorControl( Color.Red );
1176 smallColorControl[ 18 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 255 ) ), ( (Byte)( 128 ) ), ( (Byte)( 0 ) ) ) );
1177 smallColorControl[ 19 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 255 ) ), ( (Byte)( 128 ) ), ( (Byte)( 255 ) ) ) );
1178 smallColorControl[ 20 ] = new SmallColorControl( Color.Fuchsia );
1179 smallColorControl[ 21 ] = new SmallColorControl( Color.Aqua );
1180 smallColorControl[ 22 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 128 ) ), ( (Byte)( 255 ) ), ( (Byte)( 128 ) ) ) );
1181 smallColorControl[ 23 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 128 ) ), ( (Byte)( 255 ) ), ( (Byte)( 255 ) ) ) );
1182 smallColorControl[ 24 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 0 ) ), ( (Byte)( 128 ) ), ( (Byte)( 255 ) ) ) );
1183 smallColorControl[ 25 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 128 ) ), ( (Byte)( 64 ) ), ( (Byte)( 0 ) ) ) );
1184 smallColorControl[ 26 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 64 ) ), ( (Byte)( 0 ) ), ( (Byte)( 0 ) ) ) );
1185 smallColorControl[ 27 ] = new SmallColorControl( Color.Maroon );
1186 smallColorControl[ 28 ] = new SmallColorControl( Color.Purple );
1187 smallColorControl[ 29 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 0 ) ), ( (Byte)( 0 ) ), ( (Byte)( 160 ) ) ) );
1188 smallColorControl[ 30 ] = new SmallColorControl( Color.Blue );
1189 smallColorControl[ 31 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 0 ) ), ( (Byte)( 128 ) ), ( (Byte)( 64 ) ) ) );
1190 smallColorControl[ 32 ] = new SmallColorControl( Color.Green );
1191 smallColorControl[ 33 ] = new SmallColorControl( Color.Yellow );
1192 smallColorControl[ 34 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 128 ) ), ( (Byte)( 128 ) ), ( (Byte)( 192 ) ) ) );
1193 smallColorControl[ 35 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 0 ) ), ( (Byte)( 128 ) ), ( (Byte)( 192 ) ) ) );
1194 smallColorControl[ 36 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 128 ) ), ( (Byte)( 0 ) ), ( (Byte)( 64 ) ) ) );
1195 smallColorControl[ 37 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 255 ) ), ( (Byte)( 128 ) ), ( (Byte)( 192 ) ) ) );
1196 smallColorControl[ 38 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 0 ) ), ( (Byte)( 255 ) ), ( (Byte)( 128 ) ) ) );
1197 smallColorControl[ 39 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 255 ) ), ( (Byte)( 255 ) ), ( (Byte)( 128 ) ) ) );
1198 smallColorControl[ 40 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 0 ) ), ( (Byte)( 64 ) ), ( (Byte)( 0 ) ) ) );
1199 smallColorControl[ 41 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 0 ) ), ( (Byte)( 64 ) ), ( (Byte)( 64 ) ) ) );
1200 smallColorControl[ 42 ] = new SmallColorControl( Color.Navy );
1201 smallColorControl[ 43 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 0 ) ), ( (Byte)( 0 ) ), ( (Byte)( 64 ) ) ) );
1202 smallColorControl[ 44 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 64 ) ), ( (Byte)( 0 ) ), ( (Byte)( 64 ) ) ) );
1203 smallColorControl[ 45 ] = new SmallColorControl( Color.FromArgb( ( (Byte)( 64 ) ), ( (Byte)( 0 ) ), ( (Byte)( 128 ) ) ) );
1204 smallColorControl[ 46 ] = new SmallColorControl( Color.Black ); //Black
1205 smallColorControl[ 47 ] = new SmallColorControl( Color.Olive );
1207 baseColorLabel = new Label( );
1208 userColorLabel = new Label( );
1213 smallColorControl[ 0 ].Location = new Point( 0, 15 );
1214 smallColorControl[ 0 ].TabIndex = 51;
1215 smallColorControl[ 0 ].Click += new EventHandler( OnSmallColorControlClick );
1217 smallColorControl[ 1 ].Location = new Point( 50, 130 );
1218 smallColorControl[ 1 ].TabIndex = 92;
1219 smallColorControl[ 1 ].Click += new EventHandler( OnSmallColorControlClick );
1221 smallColorControl[ 2 ].Location = new Point( 75, 130 );
1222 smallColorControl[ 2 ].TabIndex = 93;
1223 smallColorControl[ 2 ].Click += new EventHandler( OnSmallColorControlClick );
1225 smallColorControl[ 3 ].Location = new Point( 175, 84 );
1226 smallColorControl[ 3 ].TabIndex = 98;
1227 smallColorControl[ 3 ].Click += new EventHandler( OnSmallColorControlClick );
1229 smallColorControl[ 4 ].Location = new Point( 125, 130 );
1230 smallColorControl[ 4 ].TabIndex = 95;
1231 smallColorControl[ 4 ].Click += new EventHandler( OnSmallColorControlClick );
1233 smallColorControl[ 5 ].Location = new Point( 100, 130 );
1234 smallColorControl[ 5 ].TabIndex = 94;
1235 smallColorControl[ 5 ].Click += new EventHandler( OnSmallColorControlClick );
1237 smallColorControl[ 6 ].Location = new Point( 175, 130 );
1238 smallColorControl[ 6 ].TabIndex = 97;
1239 smallColorControl[ 6 ].Click += new EventHandler( OnSmallColorControlClick );
1241 smallColorControl[ 7 ].Location = new Point( 150, 130 );
1242 smallColorControl[ 7 ].TabIndex = 96;
1243 smallColorControl[ 7 ].Click += new EventHandler( OnSmallColorControlClick );
1245 smallColorControl[ 8 ].Location = new Point( 25, 61 );
1246 smallColorControl[ 8 ].TabIndex = 68;
1247 smallColorControl[ 8 ].Click += new EventHandler( OnSmallColorControlClick );
1249 smallColorControl[ 9 ].Location = new Point( 0, 61 );
1250 smallColorControl[ 9 ].TabIndex = 67;
1251 smallColorControl[ 9 ].Click += new EventHandler( OnSmallColorControlClick );
1253 smallColorControl[ 10 ].Location = new Point( 75, 61 );
1254 smallColorControl[ 10 ].TabIndex = 70;
1255 smallColorControl[ 10 ].Click += new EventHandler( OnSmallColorControlClick );
1257 smallColorControl[ 11 ].Location = new Point( 50, 61 );
1258 smallColorControl[ 11 ].TabIndex = 69;
1259 smallColorControl[ 11 ].Click += new EventHandler( OnSmallColorControlClick );
1261 smallColorControl[ 12 ].Location = new Point( 125, 61 );
1262 smallColorControl[ 12 ].TabIndex = 72;
1263 smallColorControl[ 12 ].Click += new EventHandler( OnSmallColorControlClick );
1265 smallColorControl[ 13 ].Location = new Point( 100, 61 );
1266 smallColorControl[ 13 ].TabIndex = 71;
1267 smallColorControl[ 13 ].Click += new EventHandler( OnSmallColorControlClick );
1269 smallColorControl[ 14 ].Location = new Point( 175, 61 );
1270 smallColorControl[ 14 ].TabIndex = 74;
1271 smallColorControl[ 14 ].Click += new EventHandler( OnSmallColorControlClick );
1273 smallColorControl[ 15 ].Location = new Point( 50, 38 );
1274 smallColorControl[ 15 ].TabIndex = 61;
1275 smallColorControl[ 15 ].Click += new EventHandler( OnSmallColorControlClick );
1277 smallColorControl[ 16 ].Location = new Point( 75, 38 );
1278 smallColorControl[ 16 ].TabIndex = 62;
1279 smallColorControl[ 16 ].Click += new EventHandler( OnSmallColorControlClick );
1281 smallColorControl[ 17 ].Location = new Point( 0, 38 );
1282 smallColorControl[ 17 ].TabIndex = 59;
1283 smallColorControl[ 17 ].Click += new EventHandler( OnSmallColorControlClick );
1285 smallColorControl[ 18 ].Location = new Point( 25, 84 );
1286 smallColorControl[ 18 ].TabIndex = 75;
1287 smallColorControl[ 18 ].Click += new EventHandler( OnSmallColorControlClick );
1289 smallColorControl[ 19 ].Location = new Point( 175, 15 );
1290 smallColorControl[ 19 ].TabIndex = 58;
1291 smallColorControl[ 19 ].Click += new EventHandler( OnSmallColorControlClick );
1293 smallColorControl[ 20 ].Location = new Point( 175, 38 );
1294 smallColorControl[ 20 ].TabIndex = 66;
1295 smallColorControl[ 20 ].Click += new EventHandler( OnSmallColorControlClick );
1297 smallColorControl[ 21 ].Location = new Point( 100, 38 );
1298 smallColorControl[ 21 ].TabIndex = 63;
1299 smallColorControl[ 21 ].Click += new EventHandler( OnSmallColorControlClick );
1301 smallColorControl[ 22 ].Location = new Point( 50, 15 );
1302 smallColorControl[ 22 ].TabIndex = 53;
1303 smallColorControl[ 22 ].Click += new EventHandler( OnSmallColorControlClick );
1305 smallColorControl[ 23 ].Location = new Point( 100, 15 );
1306 smallColorControl[ 23 ].TabIndex = 55;
1307 smallColorControl[ 23 ].Click += new EventHandler( OnSmallColorControlClick );
1309 smallColorControl[ 24 ].Location = new Point( 125, 15 );
1310 smallColorControl[ 24 ].TabIndex = 56;
1311 smallColorControl[ 24 ].Click += new EventHandler( OnSmallColorControlClick );
1313 smallColorControl[ 25 ].Location = new Point( 25, 107 );
1314 smallColorControl[ 25 ].TabIndex = 83;
1315 smallColorControl[ 25 ].Click += new EventHandler( OnSmallColorControlClick );
1317 smallColorControl[ 26 ].Location = new Point( 0, 107 );
1318 smallColorControl[ 26 ].TabIndex = 82;
1319 smallColorControl[ 26 ].Click += new EventHandler( OnSmallColorControlClick );
1321 smallColorControl[ 27 ].Location = new Point( 0, 84 );
1322 smallColorControl[ 27 ].TabIndex = 81;
1323 smallColorControl[ 27 ].Click += new EventHandler( OnSmallColorControlClick );
1325 smallColorControl[ 28 ].Location = new Point( 150, 84 );
1326 smallColorControl[ 28 ].TabIndex = 80;
1327 smallColorControl[ 28 ].Click += new EventHandler( OnSmallColorControlClick );
1329 smallColorControl[ 29 ].Location = new Point( 125, 84 );
1330 smallColorControl[ 29 ].TabIndex = 79;
1331 smallColorControl[ 29 ].Click += new EventHandler( OnSmallColorControlClick );
1333 smallColorControl[ 30 ].Location = new Point( 100, 84 );
1334 smallColorControl[ 30 ].TabIndex = 78;
1335 smallColorControl[ 30 ].Click += new EventHandler( OnSmallColorControlClick );
1337 smallColorControl[ 31 ].Location = new Point( 75, 84 );
1338 smallColorControl[ 31 ].TabIndex = 77;
1339 smallColorControl[ 31 ].Click += new EventHandler( OnSmallColorControlClick );
1341 smallColorControl[ 32 ].Location = new Point( 50, 84 );
1342 smallColorControl[ 32 ].TabIndex = 76;
1343 smallColorControl[ 32 ].Click += new EventHandler( OnSmallColorControlClick );
1345 smallColorControl[ 33 ].Location = new Point( 25, 38 );
1346 smallColorControl[ 33 ].TabIndex = 60;
1347 smallColorControl[ 33 ].Click += new EventHandler( OnSmallColorControlClick );
1349 smallColorControl[ 34 ].Location = new Point( 150, 38 );
1350 smallColorControl[ 34 ].TabIndex = 65;
1351 smallColorControl[ 34 ].Click += new EventHandler( OnSmallColorControlClick );
1353 smallColorControl[ 35 ].Location = new Point( 125, 38 );
1354 smallColorControl[ 35 ].TabIndex = 64;
1355 smallColorControl[ 35 ].Click += new EventHandler( OnSmallColorControlClick );
1357 smallColorControl[ 36 ].Location = new Point( 150, 61 );
1358 smallColorControl[ 36 ].TabIndex = 73;
1359 smallColorControl[ 36 ].Click += new EventHandler( OnSmallColorControlClick );
1361 smallColorControl[ 37 ].Location = new Point( 150, 15 );
1362 smallColorControl[ 37 ].TabIndex = 57;
1363 smallColorControl[ 37 ].Click += new EventHandler( OnSmallColorControlClick );
1365 smallColorControl[ 38 ].Location = new Point( 75, 15 );
1366 smallColorControl[ 38 ].TabIndex = 54;
1367 smallColorControl[ 38 ].Click += new EventHandler( OnSmallColorControlClick );
1369 smallColorControl[ 39 ].Location = new Point( 25, 15 );
1370 smallColorControl[ 39 ].TabIndex = 52;
1371 smallColorControl[ 39 ].Click += new EventHandler( OnSmallColorControlClick );
1373 smallColorControl[ 40 ].Location = new Point( 50, 107 );
1374 smallColorControl[ 40 ].TabIndex = 84;
1375 smallColorControl[ 40 ].Click += new EventHandler( OnSmallColorControlClick );
1377 smallColorControl[ 41 ].Location = new Point( 75, 107 );
1378 smallColorControl[ 41 ].TabIndex = 85;
1379 smallColorControl[ 41 ].Click += new EventHandler( OnSmallColorControlClick );
1381 smallColorControl[ 42 ].Location = new Point( 100, 107 );
1382 smallColorControl[ 42 ].TabIndex = 86;
1383 smallColorControl[ 42 ].Click += new EventHandler( OnSmallColorControlClick );
1385 smallColorControl[ 43 ].Location = new Point( 125, 107 );
1386 smallColorControl[ 43 ].TabIndex = 87;
1387 smallColorControl[ 43 ].Click += new EventHandler( OnSmallColorControlClick );
1389 smallColorControl[ 44 ].Location = new Point( 150, 107 );
1390 smallColorControl[ 44 ].TabIndex = 88;
1391 smallColorControl[ 44 ].Click += new EventHandler( OnSmallColorControlClick );
1393 smallColorControl[ 45 ].Location = new Point( 175, 107 );
1394 smallColorControl[ 45 ].TabIndex = 89;
1395 smallColorControl[ 45 ].Click += new EventHandler( OnSmallColorControlClick );
1397 smallColorControl[ 46 ].Location = new Point( 0, 130 );
1398 smallColorControl[ 46 ].TabIndex = 90;
1399 smallColorControl[ 46 ].Click += new EventHandler( OnSmallColorControlClick );
1401 smallColorControl[ 47 ].Location = new Point( 25, 130 );
1402 smallColorControl[ 47 ].TabIndex = 91;
1403 smallColorControl[ 47 ].Click += new EventHandler( OnSmallColorControlClick );
1406 userSmallColorControl[ 0 ].Location = new Point( 0, 180 );
1407 userSmallColorControl[ 0 ].TabIndex = 99;
1408 userSmallColorControl[ 0 ].Click += new EventHandler( OnSmallColorControlClick );
1410 userSmallColorControl[ 1 ].Location = new Point( 0, 203 );
1411 userSmallColorControl[ 1 ].TabIndex = 108;
1412 userSmallColorControl[ 1 ].Click += new EventHandler( OnSmallColorControlClick );
1414 userSmallColorControl[ 2 ].Location = new Point( 25, 180 );
1415 userSmallColorControl[ 2 ].TabIndex = 100;
1416 userSmallColorControl[ 2 ].Click += new EventHandler( OnSmallColorControlClick );
1418 userSmallColorControl[ 3 ].Location = new Point( 25, 203 );
1419 userSmallColorControl[ 3 ].TabIndex = 109;
1420 userSmallColorControl[ 3 ].Click += new EventHandler( OnSmallColorControlClick );
1422 userSmallColorControl[ 4 ].Location = new Point( 50, 180 );
1423 userSmallColorControl[ 4 ].TabIndex = 101;
1424 userSmallColorControl[ 4 ].Click += new EventHandler( OnSmallColorControlClick );
1426 userSmallColorControl[ 5 ].Location = new Point( 50, 203 );
1427 userSmallColorControl[ 5 ].TabIndex = 110;
1428 userSmallColorControl[ 5 ].Click += new EventHandler( OnSmallColorControlClick );
1430 userSmallColorControl[ 6 ].Location = new Point( 75, 180 );
1431 userSmallColorControl[ 6 ].TabIndex = 102;
1432 userSmallColorControl[ 6 ].Click += new EventHandler( OnSmallColorControlClick );
1434 userSmallColorControl[ 7 ].Location = new Point( 75, 203 );
1435 userSmallColorControl[ 7 ].TabIndex = 111;
1436 userSmallColorControl[ 7 ].Click += new EventHandler( OnSmallColorControlClick );
1438 userSmallColorControl[ 8 ].Location = new Point( 100, 180 );
1439 userSmallColorControl[ 8 ].TabIndex = 103;
1440 userSmallColorControl[ 8 ].Click += new EventHandler( OnSmallColorControlClick );
1442 userSmallColorControl[ 9 ].Location = new Point( 100, 203 );
1443 userSmallColorControl[ 9 ].TabIndex = 112;
1444 userSmallColorControl[ 9 ].Click += new EventHandler( OnSmallColorControlClick );
1446 userSmallColorControl[ 10 ].Location = new Point( 125, 180 );
1447 userSmallColorControl[ 10 ].TabIndex = 105;
1448 userSmallColorControl[ 10 ].Click += new EventHandler( OnSmallColorControlClick );
1450 userSmallColorControl[ 11 ].Location = new Point( 125, 203 );
1451 userSmallColorControl[ 11 ].TabIndex = 113;
1452 userSmallColorControl[ 11 ].Click += new EventHandler( OnSmallColorControlClick );
1454 userSmallColorControl[ 12 ].Location = new Point( 150, 180 );
1455 userSmallColorControl[ 12 ].TabIndex = 106;
1456 userSmallColorControl[ 12 ].Click += new EventHandler( OnSmallColorControlClick );
1458 userSmallColorControl[ 13 ].Location = new Point( 150, 203 );
1459 userSmallColorControl[ 13 ].TabIndex = 114;
1460 userSmallColorControl[ 13 ].Click += new EventHandler( OnSmallColorControlClick );
1462 userSmallColorControl[ 14 ].Location = new Point( 175, 180 );
1463 userSmallColorControl[ 14 ].TabIndex = 107;
1464 userSmallColorControl[ 14 ].Click += new EventHandler( OnSmallColorControlClick );
1466 userSmallColorControl[ 15 ].Location = new Point( 175, 203 );
1467 userSmallColorControl[ 15 ].TabIndex = 115;
1468 userSmallColorControl[ 15 ].Click += new EventHandler( OnSmallColorControlClick );
1471 baseColorLabel.Location = new Point( 2, 0 );
1472 baseColorLabel.Size = new Size( 200, 12 );
1473 baseColorLabel.TabIndex = 5;
1474 baseColorLabel.Text = Locale.GetText( "Base Colours" ) + ":";
1476 userColorLabel.FlatStyle = FlatStyle.System;
1477 userColorLabel.Location = new Point( 2, 164 );
1478 userColorLabel.Size = new Size( 200, 14 );
1479 userColorLabel.TabIndex = 104;
1480 userColorLabel.Text = Locale.GetText( "User Colors" ) + ":";
1482 Controls.Add( userSmallColorControl[ 7 ] );
1483 Controls.Add( userSmallColorControl[ 6 ] );
1484 Controls.Add( userSmallColorControl[ 5 ] );
1485 Controls.Add( userSmallColorControl[ 4 ] );
1486 Controls.Add( userSmallColorControl[ 3 ] );
1487 Controls.Add( userSmallColorControl[ 2 ] );
1488 Controls.Add( userSmallColorControl[ 1 ] );
1489 Controls.Add( userSmallColorControl[ 0 ] );
1490 Controls.Add( userSmallColorControl[ 15 ] );
1491 Controls.Add( userSmallColorControl[ 14 ] );
1492 Controls.Add( userSmallColorControl[ 13 ] );
1493 Controls.Add( userSmallColorControl[ 12 ] );
1494 Controls.Add( userSmallColorControl[ 11 ] );
1495 Controls.Add( userSmallColorControl[ 10 ] );
1496 Controls.Add( userSmallColorControl[ 9 ] );
1497 Controls.Add( userSmallColorControl[ 8 ] );
1499 Controls.Add( smallColorControl[ 0 ] );
1500 Controls.Add( smallColorControl[ 3 ] );
1501 Controls.Add( smallColorControl[ 6 ] );
1502 Controls.Add( smallColorControl[ 7 ] );
1503 Controls.Add( smallColorControl[ 4 ] );
1504 Controls.Add( smallColorControl[ 5 ] );
1505 Controls.Add( smallColorControl[ 2 ] );
1506 Controls.Add( smallColorControl[ 1 ] );
1507 Controls.Add( smallColorControl[ 47 ] );
1508 Controls.Add( smallColorControl[ 46 ] );
1509 Controls.Add( smallColorControl[ 45 ] );
1510 Controls.Add( smallColorControl[ 44 ] );
1511 Controls.Add( smallColorControl[ 43 ] );
1512 Controls.Add( smallColorControl[ 42 ] );
1513 Controls.Add( smallColorControl[ 41 ] );
1514 Controls.Add( smallColorControl[ 40 ] );
1515 Controls.Add( smallColorControl[ 25 ] );
1516 Controls.Add( smallColorControl[ 26 ] );
1517 Controls.Add( smallColorControl[ 27 ] );
1518 Controls.Add( smallColorControl[ 28 ] );
1519 Controls.Add( smallColorControl[ 29 ] );
1520 Controls.Add( smallColorControl[ 30 ] );
1521 Controls.Add( smallColorControl[ 31 ] );
1522 Controls.Add( smallColorControl[ 32 ] );
1523 Controls.Add( smallColorControl[ 18 ] );
1524 Controls.Add( smallColorControl[ 14 ] );
1525 Controls.Add( smallColorControl[ 36 ] );
1526 Controls.Add( smallColorControl[ 12 ] );
1527 Controls.Add( smallColorControl[ 13 ] );
1528 Controls.Add( smallColorControl[ 10 ] );
1529 Controls.Add( smallColorControl[ 11 ] );
1530 Controls.Add( smallColorControl[ 8 ] );
1531 Controls.Add( smallColorControl[ 9 ] );
1532 Controls.Add( smallColorControl[ 20 ] );
1533 Controls.Add( smallColorControl[ 34 ] );
1534 Controls.Add( smallColorControl[ 35 ] );
1535 Controls.Add( smallColorControl[ 21 ] );
1536 Controls.Add( smallColorControl[ 16 ] );
1537 Controls.Add( smallColorControl[ 15 ] );
1538 Controls.Add( smallColorControl[ 33 ] );
1539 Controls.Add( smallColorControl[ 17 ] );
1540 Controls.Add( smallColorControl[ 19 ] );
1541 Controls.Add( smallColorControl[ 37 ] );
1542 Controls.Add( smallColorControl[ 24 ] );
1543 Controls.Add( smallColorControl[ 23 ] );
1544 Controls.Add( smallColorControl[ 38 ] );
1545 Controls.Add( smallColorControl[ 22 ] );
1546 Controls.Add( smallColorControl[ 39 ] );
1548 Controls.Add( userColorLabel );
1549 Controls.Add( baseColorLabel );
1551 Size = new Size( 212, 238 );
1552 ResumeLayout( false );
1554 selectedSmallColorControl = smallColorControl[ 46 ]; // default, Black
1555 selectedSmallColorControl.IsSelected = true;
1557 CheckIfColorIsInPanel( );
1559 panelSelected = false;
1562 private void CheckIfColorIsInPanel( )
1564 if ( colorDialogPanel.ColorDialog.Color != Color.Black )
1566 // check if we have a panel with a BackColor = ColorDialog.Color...
1567 for ( int i = 0; i < smallColorControl.Length; i++ )
1569 if ( smallColorControl[ i ].BackColor == colorDialogPanel.ColorDialog.Color )
1571 selectedSmallColorControl = smallColorControl[ i ];
1578 void OnSmallColorControlClick( object sender, EventArgs e )
1580 panelSelected = true;
1582 // previous selected smallcolorcontrol
1583 if ( selectedSmallColorControl != (SmallColorControl)sender )
1584 selectedSmallColorControl.IsSelected = false;
1586 selectedSmallColorControl = (SmallColorControl)sender;
1588 TriangleControl.CurrentBrightness = HSB.Brightness( selectedSmallColorControl.Color );
1590 colorDialogPanel.UpdateControls( selectedSmallColorControl.Color );
1591 colorDialogPanel.UpdateRGBTextBoxes( selectedSmallColorControl.Color );
1592 colorDialogPanel.UpdateHSBTextBoxes( selectedSmallColorControl.Color );
1595 public Color ColorToShow
1599 return selectedSmallColorControl.Color;
1603 public void SetUserColor( Color col )
1605 userSmallColorControl[ currentlyUsedUserSmallColorControl ].Color = col;
1607 // check if this.customColors already exists
1608 if ( customColors == null )
1610 customColors = new int[ 16 ];
1611 int white = Color.White.ToArgb( );
1613 for ( int i = 0; i < customColors.Length; i++ )
1614 customColors[ i ] = white;
1617 customColors[ currentlyUsedUserSmallColorControl ] = col.ToArgb( );
1619 // update ColorDialog dialog property
1620 colorDialogPanel.ColorDialog.CustomColors = customColors;
1622 currentlyUsedUserSmallColorControl++;
1623 if ( currentlyUsedUserSmallColorControl > 15 )
1624 currentlyUsedUserSmallColorControl = 0;
1627 public void SetCustomColors( )
1629 int[] customColors = colorDialogPanel.ColorDialog.CustomColors;
1631 for ( int i = 0; i < customColors.Length; i++ )
1633 userSmallColorControl[ i ].Color = Color.FromArgb( customColors[ i ] );
1638 internal class ColorMatrixControl : Panel
1640 internal class DrawingBitmap
1642 private Bitmap bitmap;
1644 public DrawingBitmap( )
1646 bitmap = new Bitmap( 180, 191 );
1648 float hueadd = 241.0f / 178.0f;
1649 float satsub = 241.0f / 189.0f;
1650 float satpos = 240.0f;
1652 // paint the matrix to the bitmap
1653 for ( int height = 0; height < 191; height++ )
1655 float huepos = 0.0f;
1657 for ( int width = 0; width < 180; width++ )
1659 HSB hsb = new HSB( );
1661 hsb.hue = (int)huepos;
1662 hsb.sat = (int)satpos;
1663 hsb.bri = 120; // paint it with 120 to get a nice bitmap
1665 bitmap.SetPixel( width, height, HSB.HSB2RGB( hsb.hue, hsb.sat, hsb.bri ) );
1674 public Bitmap Bitmap
1688 internal class CrossCursor
1690 private Bitmap bitmap;
1692 private Color cursorColor;
1694 public CrossCursor( )
1696 bitmap = new Bitmap( 22, 22 );
1698 cursorColor = Color.Black;
1705 using( Pen pen = new Pen( ThemeEngine.Current.ResPool.GetSolidBrush( cursorColor ), 3 ) )
1707 using( Graphics graphics = Graphics.FromImage( bitmap ) )
1709 graphics.DrawLine( pen, 11, 0, 11, 7 );
1710 graphics.DrawLine( pen, 11, 14, 11, 21 );
1711 graphics.DrawLine( pen, 0, 11, 7, 11 );
1712 graphics.DrawLine( pen, 14, 11, 21, 11 );
1717 public Bitmap Bitmap
1730 public Color CursorColor
1734 cursorColor = value;
1744 private DrawingBitmap drawingBitmap = new DrawingBitmap( );
1746 private CrossCursor crossCursor = new CrossCursor();
1748 private bool mouseButtonDown = false;
1750 private bool drawCross = true;
1752 private Color color;
1754 private int currentXPos;
1755 private int currentYPos;
1757 private const float xstep = 240.0f/178.0f;
1758 private const float ystep = 240.0f/189.0f;
1760 private ColorDialogPanel colorDialogPanel;
1762 public ColorMatrixControl( ColorDialogPanel colorDialogPanel )
1764 this.colorDialogPanel = colorDialogPanel;
1768 BorderStyle = BorderStyle.Fixed3D;
1769 Location = new Point( 0, 0 );
1770 Size = new Size( 179, 190 );
1773 //BackColor = SystemColors.Control;
1774 Size = new Size( 179, 190 );
1776 ResumeLayout( false );
1778 SetStyle( ControlStyles.DoubleBuffer, true );
1779 SetStyle( ControlStyles.AllPaintingInWmPaint, true );
1780 SetStyle( ControlStyles.UserPaint, true );
1783 protected override void OnPaint( PaintEventArgs e )
1790 private void Draw( PaintEventArgs e )
1792 Bitmap bmp = new Bitmap( drawingBitmap.Bitmap );
1794 e.Graphics.DrawImage( bmp, 0, 0 );
1796 // drawCross is false if the mouse gets moved...
1799 e.Graphics.DrawImage( crossCursor.Bitmap, currentXPos - 11 , currentYPos - 11 );
1803 protected override void OnMouseDown( MouseEventArgs e )
1805 mouseButtonDown = true;
1817 base.OnMouseDown( e );
1820 protected override void OnMouseMove( MouseEventArgs e )
1822 if ( mouseButtonDown )
1823 if ( ( e.X < 178 && e.X >= 0 ) && ( e.Y < 189 && e.Y >= 0 ) ) // 177 189
1830 base.OnMouseMove( e );
1833 protected override void OnMouseUp( MouseEventArgs e )
1835 mouseButtonDown = false;
1841 public Color ColorToShow
1847 HSB hsb = HSB.RGB2HSB( color );
1849 currentXPos = (int)( (float)hsb.hue / xstep );
1850 currentYPos = 189 - (int)( (float)hsb.sat / ystep );
1852 if ( currentXPos < 0 )
1854 if ( currentYPos < 0 )
1864 private Color GetColorFromHSB( )
1866 int hue = (int)( (float)currentXPos * xstep );
1867 int sat = 240 - ( (int)( (float)currentYPos * ystep ) );
1868 int bri = TriangleControl.CurrentBrightness;
1870 return HSB.HSB2RGB( hue, sat, bri );
1873 private void UpdateControls( )
1875 Color tmpColor = GetColorFromHSB( );
1877 // update the brightness control
1878 colorDialogPanel.BrightnessControl.ShowColor( (int)( (float)currentXPos * xstep ), 240 - ( (int)( (float)currentYPos * ystep ) ) );
1880 // update saturation text box
1881 int satvalue = ( 240 - ( (int)( (float)currentYPos * ystep ) ) );
1882 satvalue = satvalue == 240 ? 239 : satvalue;
1883 colorDialogPanel.SatTextBox.Text = satvalue.ToString( );
1885 // update hue text box
1886 colorDialogPanel.HueTextBox.Text = ( (int)( (float)currentXPos * xstep ) ).ToString( );
1888 // update the main selected color panel
1889 colorDialogPanel.SelectedColorPanel.BackColor = tmpColor;
1891 // and finally the rgb text boxes
1892 colorDialogPanel.UpdateRGBTextBoxes( tmpColor );
1897 internal class BrightnessControl : Panel
1899 internal class DrawingBitmap
1901 private Bitmap bitmap;
1903 public DrawingBitmap( )
1905 bitmap = new Bitmap( 14, 190 );
1908 public Bitmap Bitmap
1921 // only hue and saturation are needed.
1922 // color will be computed with an iteration
1923 public void Draw( int hue, int sat )
1925 float brisub = 240.0f / 190.0f;
1928 for ( int height = 0; height < 190; height++ )
1930 for ( int width = 0; width < 14; width++ )
1932 Color pixcolor = HSB.HSB2RGB( hue, sat, (int)bri );
1933 bitmap.SetPixel( width, height, pixcolor );
1940 private const float step = 240.0f/189.0f;
1942 private DrawingBitmap bitmap;
1944 private Color color;
1946 private ColorDialogPanel colorDialogPanel;
1948 public BrightnessControl( ColorDialogPanel colorDialogPanel )
1950 this.colorDialogPanel = colorDialogPanel;
1954 BorderStyle = BorderStyle.Fixed3D;
1955 Location = new Point( 0, 0 );
1956 Size = new Size( 14, 190 );
1959 Size = new Size( 14, 190 );
1960 ResumeLayout( false );
1962 bitmap = new DrawingBitmap( );
1964 SetStyle( ControlStyles.DoubleBuffer, true );
1965 SetStyle( ControlStyles.AllPaintingInWmPaint, true );
1966 SetStyle( ControlStyles.UserPaint, true );
1970 protected override void OnPaint( PaintEventArgs e )
1972 e.Graphics.DrawImage( bitmap.Bitmap, 0, 0 );
1977 protected override void OnMouseDown( MouseEventArgs e )
1979 colorDialogPanel.TriangleControl.TrianglePosition = (int)( (float)( 189 - e.Y ) * step );
1981 base.OnMouseDown( e );
1984 // this one is for ColorMatrixControl
1985 public void ShowColor( int hue, int sat )
1987 bitmap.Draw( hue, sat );
1992 // this one for the other controls
1993 public Color ColorToShow
1998 HSB.GetHueSaturation( value, out hue, out sat );
1999 bitmap.Draw( hue, sat );
2007 internal class TriangleControl : Panel
2009 private bool mouseButtonDown = false;
2011 private int currentTrianglePosition = 195;
2012 // private Rectangle clipRectangle;
2014 private const float briStep = 239.0f/186.0f;
2016 private static int currentBrightness = 0;
2018 private ColorDialogPanel colorDialogPanel;
2020 public TriangleControl( ColorDialogPanel colorDialogPanel )
2022 this.colorDialogPanel = colorDialogPanel;
2024 Size = new Size( 16, 203 );
2026 SetStyle( ControlStyles.DoubleBuffer, true );
2027 SetStyle( ControlStyles.AllPaintingInWmPaint, true );
2028 SetStyle( ControlStyles.UserPaint, true );
2031 public static int CurrentBrightness
2035 currentBrightness = value;
2040 return currentBrightness;
2044 protected override void OnPaint( PaintEventArgs e )
2051 private void Draw( PaintEventArgs e )
2053 e.Graphics.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( BackColor ), new Rectangle( 0, 0, 16, 203 ) );
2055 Point[] trianglePoints = new Point[ 3 ]
2057 new Point( 0, currentTrianglePosition ),
2058 new Point( 8, currentTrianglePosition - 8 ),
2059 new Point( 8, currentTrianglePosition + 8 )
2062 e.Graphics.FillPolygon( ThemeEngine.Current.ResPool.GetSolidBrush( Color.Black ), trianglePoints );
2065 protected override void OnMouseDown( MouseEventArgs e )
2067 if ( e.Y > 195 || e.Y < 9 ) return; // helper until Cursor.Clip works
2069 mouseButtonDown = true;
2070 currentTrianglePosition = e.Y;
2072 // Cursor.Clip doesn't yet work in Managed.Windows.Forms
2073 // clipRectangle = Cursor.Clip;
2074 // Point p = Location;
2079 // Cursor.Clip = new Rectangle( Parent.PointToScreen( p ), s );
2081 colorDialogPanel.BriTextBox.Text = TrianglePosition.ToString( );
2082 colorDialogPanel.UpdateFromHSBTextBoxes( );
2087 base.OnMouseDown( e );
2090 protected override void OnMouseMove( MouseEventArgs e )
2092 if ( mouseButtonDown )
2093 if ( e.Y < 196 && e.Y > 8 )
2095 currentTrianglePosition = e.Y;
2097 colorDialogPanel.BriTextBox.Text = TrianglePosition.ToString( );
2098 colorDialogPanel.UpdateFromHSBTextBoxes( );
2104 base.OnMouseMove( e );
2107 protected override void OnMouseUp( MouseEventArgs e )
2109 mouseButtonDown = false;
2110 // Cursor.Clip = clipRectangle;
2112 base.OnMouseUp( e );
2115 public int TrianglePosition
2119 float tmp = (float)( currentTrianglePosition - 9 );
2120 tmp = tmp * briStep;
2122 int retval = 239 - (int)tmp;
2124 TriangleControl.CurrentBrightness = retval;
2131 float tmp = (float)value / briStep;
2132 currentTrianglePosition = 186 - (int)tmp + 9;
2134 colorDialogPanel.BriTextBox.Text = TrianglePosition.ToString( );
2135 colorDialogPanel.UpdateFromHSBTextBoxes( );
2142 public Color ColorToShow
2146 TrianglePosition = HSB.Brightness( value );