File: ColorChooser.cs

package info (click to toggle)
quickroute-gps 2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 19,576 kB
  • sloc: cs: 74,488; makefile: 72; sh: 43
file content (1568 lines) | stat: -rw-r--r-- 52,880 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace QuickRoute.Controls.Forms
{

  public class ColorChooser : Form
	{
		internal System.Windows.Forms.Label lblBlue;
		internal System.Windows.Forms.Label lblGreen;
		internal System.Windows.Forms.Label lblRed;
		internal System.Windows.Forms.Label lblBrightness;
		internal System.Windows.Forms.Label lblSaturation;
		internal System.Windows.Forms.Label lblHue;
		internal System.Windows.Forms.HScrollBar hsbBlue;
		internal System.Windows.Forms.HScrollBar hsbGreen;
		internal System.Windows.Forms.HScrollBar hsbRed;
		internal System.Windows.Forms.HScrollBar hsbBrightness;
		internal System.Windows.Forms.HScrollBar hsbSaturation;
		internal System.Windows.Forms.HScrollBar hsbHue;
		internal System.Windows.Forms.Button btnCancel;
		internal System.Windows.Forms.Button btnOK;
		internal System.Windows.Forms.Label Label3;
		internal System.Windows.Forms.Label Label7;
		internal System.Windows.Forms.Panel pnlColor;
		internal System.Windows.Forms.Label Label6;
		internal System.Windows.Forms.Label Label1;
		internal System.Windows.Forms.Label Label5;
		internal System.Windows.Forms.Panel pnlSelectedColor;
		internal System.Windows.Forms.Panel pnlBrightness;
		internal System.Windows.Forms.Label Label2;
    internal Label lblAlpha;
    internal HScrollBar hsbAlpha;
    internal Label label8;
    internal Panel pnlAlpha;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public ColorChooser()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ColorChooser));
      this.lblBlue = new System.Windows.Forms.Label();
      this.lblGreen = new System.Windows.Forms.Label();
      this.lblRed = new System.Windows.Forms.Label();
      this.lblBrightness = new System.Windows.Forms.Label();
      this.lblSaturation = new System.Windows.Forms.Label();
      this.lblHue = new System.Windows.Forms.Label();
      this.hsbBlue = new System.Windows.Forms.HScrollBar();
      this.hsbGreen = new System.Windows.Forms.HScrollBar();
      this.hsbRed = new System.Windows.Forms.HScrollBar();
      this.hsbBrightness = new System.Windows.Forms.HScrollBar();
      this.hsbSaturation = new System.Windows.Forms.HScrollBar();
      this.hsbHue = new System.Windows.Forms.HScrollBar();
      this.btnCancel = new System.Windows.Forms.Button();
      this.btnOK = new System.Windows.Forms.Button();
      this.Label3 = new System.Windows.Forms.Label();
      this.Label7 = new System.Windows.Forms.Label();
      this.pnlColor = new System.Windows.Forms.Panel();
      this.Label6 = new System.Windows.Forms.Label();
      this.Label1 = new System.Windows.Forms.Label();
      this.Label5 = new System.Windows.Forms.Label();
      this.pnlSelectedColor = new System.Windows.Forms.Panel();
      this.pnlBrightness = new System.Windows.Forms.Panel();
      this.Label2 = new System.Windows.Forms.Label();
      this.lblAlpha = new System.Windows.Forms.Label();
      this.hsbAlpha = new System.Windows.Forms.HScrollBar();
      this.label8 = new System.Windows.Forms.Label();
      this.pnlAlpha = new System.Windows.Forms.Panel();
      this.SuspendLayout();
      // 
      // lblBlue
      // 
      this.lblBlue.AccessibleDescription = null;
      this.lblBlue.AccessibleName = null;
      resources.ApplyResources(this.lblBlue, "lblBlue");
      this.lblBlue.Name = "lblBlue";
      // 
      // lblGreen
      // 
      this.lblGreen.AccessibleDescription = null;
      this.lblGreen.AccessibleName = null;
      resources.ApplyResources(this.lblGreen, "lblGreen");
      this.lblGreen.Name = "lblGreen";
      // 
      // lblRed
      // 
      this.lblRed.AccessibleDescription = null;
      this.lblRed.AccessibleName = null;
      resources.ApplyResources(this.lblRed, "lblRed");
      this.lblRed.Name = "lblRed";
      // 
      // lblBrightness
      // 
      this.lblBrightness.AccessibleDescription = null;
      this.lblBrightness.AccessibleName = null;
      resources.ApplyResources(this.lblBrightness, "lblBrightness");
      this.lblBrightness.Name = "lblBrightness";
      // 
      // lblSaturation
      // 
      this.lblSaturation.AccessibleDescription = null;
      this.lblSaturation.AccessibleName = null;
      resources.ApplyResources(this.lblSaturation, "lblSaturation");
      this.lblSaturation.Name = "lblSaturation";
      // 
      // lblHue
      // 
      this.lblHue.AccessibleDescription = null;
      this.lblHue.AccessibleName = null;
      resources.ApplyResources(this.lblHue, "lblHue");
      this.lblHue.Name = "lblHue";
      // 
      // hsbBlue
      // 
      this.hsbBlue.AccessibleDescription = null;
      this.hsbBlue.AccessibleName = null;
      resources.ApplyResources(this.hsbBlue, "hsbBlue");
      this.hsbBlue.BackgroundImage = null;
      this.hsbBlue.Font = null;
      this.hsbBlue.LargeChange = 1;
      this.hsbBlue.Maximum = 255;
      this.hsbBlue.Name = "hsbBlue";
      this.hsbBlue.Scroll += new System.Windows.Forms.ScrollEventHandler(this.HandleARGBScroll);
      // 
      // hsbGreen
      // 
      this.hsbGreen.AccessibleDescription = null;
      this.hsbGreen.AccessibleName = null;
      resources.ApplyResources(this.hsbGreen, "hsbGreen");
      this.hsbGreen.BackgroundImage = null;
      this.hsbGreen.Font = null;
      this.hsbGreen.LargeChange = 1;
      this.hsbGreen.Maximum = 255;
      this.hsbGreen.Name = "hsbGreen";
      this.hsbGreen.Scroll += new System.Windows.Forms.ScrollEventHandler(this.HandleARGBScroll);
      // 
      // hsbRed
      // 
      this.hsbRed.AccessibleDescription = null;
      this.hsbRed.AccessibleName = null;
      resources.ApplyResources(this.hsbRed, "hsbRed");
      this.hsbRed.BackgroundImage = null;
      this.hsbRed.Font = null;
      this.hsbRed.LargeChange = 1;
      this.hsbRed.Maximum = 255;
      this.hsbRed.Name = "hsbRed";
      this.hsbRed.Scroll += new System.Windows.Forms.ScrollEventHandler(this.HandleARGBScroll);
      // 
      // hsbBrightness
      // 
      this.hsbBrightness.AccessibleDescription = null;
      this.hsbBrightness.AccessibleName = null;
      resources.ApplyResources(this.hsbBrightness, "hsbBrightness");
      this.hsbBrightness.BackgroundImage = null;
      this.hsbBrightness.Font = null;
      this.hsbBrightness.LargeChange = 1;
      this.hsbBrightness.Maximum = 255;
      this.hsbBrightness.Name = "hsbBrightness";
      this.hsbBrightness.Scroll += new System.Windows.Forms.ScrollEventHandler(this.HandleHSVScroll);
      // 
      // hsbSaturation
      // 
      this.hsbSaturation.AccessibleDescription = null;
      this.hsbSaturation.AccessibleName = null;
      resources.ApplyResources(this.hsbSaturation, "hsbSaturation");
      this.hsbSaturation.BackgroundImage = null;
      this.hsbSaturation.Font = null;
      this.hsbSaturation.LargeChange = 1;
      this.hsbSaturation.Maximum = 255;
      this.hsbSaturation.Name = "hsbSaturation";
      this.hsbSaturation.Scroll += new System.Windows.Forms.ScrollEventHandler(this.HandleHSVScroll);
      // 
      // hsbHue
      // 
      this.hsbHue.AccessibleDescription = null;
      this.hsbHue.AccessibleName = null;
      resources.ApplyResources(this.hsbHue, "hsbHue");
      this.hsbHue.BackgroundImage = null;
      this.hsbHue.Font = null;
      this.hsbHue.LargeChange = 1;
      this.hsbHue.Maximum = 255;
      this.hsbHue.Name = "hsbHue";
      this.hsbHue.Scroll += new System.Windows.Forms.ScrollEventHandler(this.HandleHSVScroll);
      // 
      // btnCancel
      // 
      this.btnCancel.AccessibleDescription = null;
      this.btnCancel.AccessibleName = null;
      resources.ApplyResources(this.btnCancel, "btnCancel");
      this.btnCancel.BackgroundImage = null;
      this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
      this.btnCancel.Font = null;
      this.btnCancel.Name = "btnCancel";
      // 
      // btnOK
      // 
      this.btnOK.AccessibleDescription = null;
      this.btnOK.AccessibleName = null;
      resources.ApplyResources(this.btnOK, "btnOK");
      this.btnOK.BackgroundImage = null;
      this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
      this.btnOK.Name = "btnOK";
      // 
      // Label3
      // 
      this.Label3.AccessibleDescription = null;
      this.Label3.AccessibleName = null;
      resources.ApplyResources(this.Label3, "Label3");
      this.Label3.Name = "Label3";
      // 
      // Label7
      // 
      this.Label7.AccessibleDescription = null;
      this.Label7.AccessibleName = null;
      resources.ApplyResources(this.Label7, "Label7");
      this.Label7.Name = "Label7";
      // 
      // pnlColor
      // 
      this.pnlColor.AccessibleDescription = null;
      this.pnlColor.AccessibleName = null;
      resources.ApplyResources(this.pnlColor, "pnlColor");
      this.pnlColor.BackgroundImage = null;
      this.pnlColor.Font = null;
      this.pnlColor.Name = "pnlColor";
      // 
      // Label6
      // 
      this.Label6.AccessibleDescription = null;
      this.Label6.AccessibleName = null;
      resources.ApplyResources(this.Label6, "Label6");
      this.Label6.Name = "Label6";
      // 
      // Label1
      // 
      this.Label1.AccessibleDescription = null;
      this.Label1.AccessibleName = null;
      resources.ApplyResources(this.Label1, "Label1");
      this.Label1.Name = "Label1";
      // 
      // Label5
      // 
      this.Label5.AccessibleDescription = null;
      this.Label5.AccessibleName = null;
      resources.ApplyResources(this.Label5, "Label5");
      this.Label5.Name = "Label5";
      // 
      // pnlSelectedColor
      // 
      this.pnlSelectedColor.AccessibleDescription = null;
      this.pnlSelectedColor.AccessibleName = null;
      resources.ApplyResources(this.pnlSelectedColor, "pnlSelectedColor");
      this.pnlSelectedColor.BackgroundImage = null;
      this.pnlSelectedColor.Font = null;
      this.pnlSelectedColor.Name = "pnlSelectedColor";
      // 
      // pnlBrightness
      // 
      this.pnlBrightness.AccessibleDescription = null;
      this.pnlBrightness.AccessibleName = null;
      resources.ApplyResources(this.pnlBrightness, "pnlBrightness");
      this.pnlBrightness.BackgroundImage = null;
      this.pnlBrightness.Font = null;
      this.pnlBrightness.Name = "pnlBrightness";
      // 
      // Label2
      // 
      this.Label2.AccessibleDescription = null;
      this.Label2.AccessibleName = null;
      resources.ApplyResources(this.Label2, "Label2");
      this.Label2.Name = "Label2";
      // 
      // lblAlpha
      // 
      this.lblAlpha.AccessibleDescription = null;
      this.lblAlpha.AccessibleName = null;
      resources.ApplyResources(this.lblAlpha, "lblAlpha");
      this.lblAlpha.Name = "lblAlpha";
      // 
      // hsbAlpha
      // 
      this.hsbAlpha.AccessibleDescription = null;
      this.hsbAlpha.AccessibleName = null;
      resources.ApplyResources(this.hsbAlpha, "hsbAlpha");
      this.hsbAlpha.BackgroundImage = null;
      this.hsbAlpha.Font = null;
      this.hsbAlpha.LargeChange = 1;
      this.hsbAlpha.Maximum = 255;
      this.hsbAlpha.Name = "hsbAlpha";
      this.hsbAlpha.Scroll += new System.Windows.Forms.ScrollEventHandler(this.HandleARGBScroll);
      // 
      // label8
      // 
      this.label8.AccessibleDescription = null;
      this.label8.AccessibleName = null;
      resources.ApplyResources(this.label8, "label8");
      this.label8.Name = "label8";
      // 
      // pnlAlpha
      // 
      this.pnlAlpha.AccessibleDescription = null;
      this.pnlAlpha.AccessibleName = null;
      resources.ApplyResources(this.pnlAlpha, "pnlAlpha");
      this.pnlAlpha.BackgroundImage = null;
      this.pnlAlpha.Font = null;
      this.pnlAlpha.Name = "pnlAlpha";
      // 
      // ColorChooser
      // 
      this.AcceptButton = this.btnOK;
      this.AccessibleDescription = null;
      this.AccessibleName = null;
      resources.ApplyResources(this, "$this");
      this.BackgroundImage = null;
      this.CancelButton = this.btnCancel;
      this.Controls.Add(this.pnlAlpha);
      this.Controls.Add(this.lblAlpha);
      this.Controls.Add(this.hsbAlpha);
      this.Controls.Add(this.label8);
      this.Controls.Add(this.lblBlue);
      this.Controls.Add(this.lblGreen);
      this.Controls.Add(this.lblRed);
      this.Controls.Add(this.lblBrightness);
      this.Controls.Add(this.lblSaturation);
      this.Controls.Add(this.lblHue);
      this.Controls.Add(this.hsbBlue);
      this.Controls.Add(this.hsbGreen);
      this.Controls.Add(this.hsbRed);
      this.Controls.Add(this.hsbBrightness);
      this.Controls.Add(this.hsbSaturation);
      this.Controls.Add(this.hsbHue);
      this.Controls.Add(this.btnCancel);
      this.Controls.Add(this.btnOK);
      this.Controls.Add(this.Label3);
      this.Controls.Add(this.Label7);
      this.Controls.Add(this.pnlColor);
      this.Controls.Add(this.Label6);
      this.Controls.Add(this.Label1);
      this.Controls.Add(this.Label5);
      this.Controls.Add(this.pnlSelectedColor);
      this.Controls.Add(this.pnlBrightness);
      this.Controls.Add(this.Label2);
      this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
      this.Icon = null;
      this.MaximizeBox = false;
      this.MinimizeBox = false;
      this.Name = "ColorChooser";
      this.ShowIcon = false;
      this.ShowInTaskbar = false;
      this.Load += new System.EventHandler(this.ColorChooser2_Load);
      this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseUp);
      this.Paint += new System.Windows.Forms.PaintEventHandler(this.ColorChooser2_Paint);
      this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.HandleMouse);
      this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.HandleMouse);
      this.ResumeLayout(false);

		}
		#endregion

		private enum ChangeStyle
		{
			MouseMove,
			ARGB,
			AHSV,
			None
		}

		private ChangeStyle changeType = ChangeStyle.None;
		private Point selectedPoint;

		private ColorWheel myColorWheel;
		private ColorHandler.ARGB ARGB;
		private ColorHandler.AHSV AHSV;

		private void ColorChooser2_Load(object sender, System.EventArgs e)
		{
			// Turn on double-buffering, so the form looks better. 
			this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
			this.SetStyle(ControlStyles.UserPaint, true);
			this.SetStyle(ControlStyles.DoubleBuffer, true);

			// These properties are set in design view, as well, but they
			// have to be set to false in order for the Paint
			// event to be able to display their contents.
			// Never hurts to make sure they're invisible.
			pnlSelectedColor.Visible = false;
      pnlBrightness.Visible = false;
      pnlAlpha.Visible = false;
      pnlColor.Visible = false;

			// Calculate the coordinates of the three
			// required regions on the form.
			Rectangle SelectedColorRectangle =  new Rectangle(pnlSelectedColor.Location, pnlSelectedColor.Size);
      Rectangle BrightnessRectangle = new Rectangle(pnlBrightness.Location, pnlBrightness.Size);
      Rectangle AlphaRectangle = new Rectangle(pnlAlpha.Location, pnlAlpha.Size);
      Rectangle ColorRectangle = new Rectangle(pnlColor.Location, pnlColor.Size);

			// Export the new ColorWheel class, indicating
			// the locations of the color wheel itself, the
			// brightness area, and the position of the selected color.
      myColorWheel = new ColorWheel(ColorRectangle, BrightnessRectangle, AlphaRectangle, SelectedColorRectangle);
			myColorWheel.ColorChanged += this.myColorWheel_ColorChanged;

			// Set the RGB and HSV values 
			// of the NumericUpDown controls.
			SetARGB(ARGB);
			SetAHSV(AHSV);		
		}

		private void HandleMouse(object sender,  MouseEventArgs e)
		{
			// If you have the left mouse button down, 
			// then update the selectedPoint value and 
			// force a repaint of the color wheel.
			if ( e.Button == MouseButtons.Left ) 
			{
				changeType = ChangeStyle.MouseMove;
				selectedPoint = new Point(e.X, e.Y);
				this.Invalidate();
			}
		}

		private void frmMain_MouseUp(object sender,  MouseEventArgs e)
		{
			myColorWheel.SetMouseUp();
			changeType = ChangeStyle.None;
		}

		private void SetARGBLabels(ColorHandler.ARGB ARGB) 
		{
      RefreshText(lblAlpha, ARGB.Alpha);
      RefreshText(lblRed, ARGB.Red);
      RefreshText(lblBlue, ARGB.Blue);
			RefreshText(lblGreen, ARGB.Green);
		}

		private void SetAHSVLabels(ColorHandler.AHSV AHSV) 
		{
			RefreshText(lblHue, AHSV.Hue);
			RefreshText(lblSaturation, AHSV.Saturation);
			RefreshText(lblBrightness, AHSV.Value);
		}

		private void SetARGB(ColorHandler.ARGB ARGB) 
		{
			// Update the RGB values on the form.
      RefreshValue(hsbAlpha, ARGB.Alpha);
      RefreshValue(hsbRed, ARGB.Red);
      RefreshValue(hsbBlue, ARGB.Blue);
			RefreshValue(hsbGreen, ARGB.Green);
			SetARGBLabels(ARGB);
			}

		private void SetAHSV( ColorHandler.AHSV AHSV) 
		{
			// Update the HSV values on the form.
			RefreshValue(hsbHue, AHSV.Hue);
			RefreshValue(hsbSaturation, AHSV.Saturation);
			RefreshValue(hsbBrightness, AHSV.Value);
			SetAHSVLabels(AHSV);
			}

		private void RefreshValue(HScrollBar hsb, int value) 
		{
			hsb.Value = value;
		}

		private void RefreshText(Label lbl, int value) 
		{
			lbl.Text = value.ToString();
		}

		public Color Color  
		{
			// Get or set the color to be
			// displayed in the color wheel.
			get 
			{
				return myColorWheel.Color;
			}

			set 
			{
				// Indicate the color change type. Either RGB or HSV
				// will cause the color wheel to update the position
				// of the pointer.
				changeType = ChangeStyle.ARGB;
				ARGB = new ColorHandler.ARGB(value.A, value.R, value.G, value.B);
				AHSV = ColorHandler.ARGBtoAHSV(ARGB);
			}
		}

		private void myColorWheel_ColorChanged(object sender,  ColorChangedEventArgs e)  
		{
			SetARGB(e.ARGB);
			SetAHSV(e.AHSV);
		}

		private void HandleHSVScroll(object sender,  ScrollEventArgs e)  
			// If the H, S, or V values change, use this 
			// code to update the RGB values and invalidate
			// the color wheel (so it updates the pointers).
			// Check the isInUpdate flag to avoid recursive events
			// when you update the NumericUpdownControls.
		{
			changeType = ChangeStyle.AHSV;
			AHSV = new ColorHandler.AHSV(hsbAlpha.Value, hsbHue.Value, hsbSaturation.Value, hsbBrightness.Value);
			SetARGB(ColorHandler.AHSVtoARGB(AHSV));
			SetAHSVLabels(AHSV);
			this.Invalidate();
		}

		private void HandleARGBScroll(object sender, ScrollEventArgs e)
		{
			// If the R, G, or B values change, use this 
			// code to update the HSV values and invalidate
			// the color wheel (so it updates the pointers).
			// Check the isInUpdate flag to avoid recursive events
			// when you update the NumericUpdownControls.
			changeType = ChangeStyle.ARGB;
			ARGB = new ColorHandler.ARGB(hsbAlpha.Value, hsbRed.Value, hsbGreen.Value, hsbBlue.Value);
			SetAHSV(ColorHandler.ARGBtoAHSV(ARGB));
			SetARGBLabels(ARGB);
			this.Invalidate();
		}

		private void ColorChooser2_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
			// Depending on the circumstances, force a repaint
			// of the color wheel passing different information.
			switch (changeType)
			{
				case ChangeStyle.AHSV:
					myColorWheel.Draw(e.Graphics, AHSV);
					break;
				case ChangeStyle.MouseMove:
				case ChangeStyle.None:
					myColorWheel.Draw(e.Graphics, selectedPoint);
					break;
				case ChangeStyle.ARGB:
					myColorWheel.Draw(e.Graphics, ARGB);
					break;
			}
		}
	}

  public class ColorWheel : IDisposable
  {

    // These resources should be disposed
    // of when you're done with them.
    private Graphics g;
    private Region colorRegion;
    private Region brightnessRegion;
    private Region alphaRegion;
    private Bitmap colorImage;

    public EventHandler<ColorChangedEventArgs> ColorChanged;

    // Keep track of the current mouse state. 
    public enum MouseState
    {
      MouseUp,
      ClickOnColor,
      DragInColor,
      ClickOnBrightness,
      DragInBrightness,
      ClickOnAlpha,
      DragInAlpha,
      ClickOutsideRegion,
      DragOutsideRegion,
    }
    private MouseState currentState = MouseState.MouseUp;

    // The code needs to convert back and forth between 
    // degrees and radians. There are 2*PI radians in a 
    // full circle, and 360 degrees. This constant allows
    // you to convert back and forth.
    private const double DEGREES_PER_RADIAN = 180.0 / Math.PI;

    // COLOR_COUNT represents the number of distinct colors
    // used to create the circular gradient. Its value 
    // is somewhat arbitrary -- change this to 6, for 
    // example, to see what happens. 1536 (6 * 256) seems 
    // a good compromise -- it's enough to get a full 
    // range of colors, but it doesn't overwhelm the processor
    // attempting to generate the image. The color wheel
    // contains 6 sections, and each section displays 
    // 256 colors. Seems like a reasonable compromise.
    private const int COLOR_COUNT = 6 * 256;

    private Point centerPoint;
    private int radius;

    private Rectangle colorRectangle;
    private Rectangle brightnessRectangle;
    private Rectangle alphaRectangle;
    private Rectangle selectedColorRectangle;
    private int brightnessX;
    private double brightnessScaling;
    private int alphaX;
    private double alphaScaling;

    // selectedColor is the actual value selected
    // by the user. fullColor is the same color, 
    // with its brightness set to 255.
    private Color selectedColor = Color.White;
    private Color fullColor;

    private ColorHandler.ARGB ARGB;
    private ColorHandler.AHSV AHSV;

    // Locations for the two "pointers" on the form.
    private Point colorPoint;
    private Point brightnessPoint;
    private Point alphaPoint;

    private int brightness;
    private int brightnessMin;
    private int brightnessMax;

    private int alpha;
    private int alphaMin;
    private int alphaMax;

    public ColorWheel(Rectangle colorRectangle, Rectangle brightnessRectangle, Rectangle alphaRectangle, Rectangle selectedColorRectangle)
    {

      // Caller must provide locations for color wheel
      // (colorRectangle), brightness "strip" (brightnessRectangle),
      // alpha "strip" (alphaRectangle)
      // and location to display selected color (selectedColorRectangle).

      using (GraphicsPath path = new GraphicsPath())
      {
        // Store away locations for later use. 
        this.colorRectangle = colorRectangle;
        this.brightnessRectangle = brightnessRectangle;
        this.alphaRectangle = alphaRectangle;
        this.selectedColorRectangle = selectedColorRectangle;

        // Calculate the center of the circle.
        // Start with the location, then offset
        // the point by the radius.
        // Use the smaller of the width and height of
        // the colorRectangle value.
        this.radius = (int)Math.Min(colorRectangle.Width, colorRectangle.Height) / 2;
        this.centerPoint = colorRectangle.Location;
        this.centerPoint.Offset(radius, radius);

        // Start the pointer in the center.
        this.colorPoint = this.centerPoint;

        // Export a region corresponding to the color circle.
        // Code uses this later to determine if a specified
        // point is within the region, using the IsVisible 
        // method.
        path.AddEllipse(colorRectangle);
        colorRegion = new Region(path);

        // set the range for the brightness selector.
        this.brightnessMin = this.brightnessRectangle.Top;
        this.brightnessMax = this.brightnessRectangle.Bottom;

        // Export a region corresponding to the
        // brightness rectangle, with a little extra 
        // "breathing room". 

        path.AddRectangle(new Rectangle(brightnessRectangle.Left, brightnessRectangle.Top - 10, brightnessRectangle.Width + 10, brightnessRectangle.Height + 20));
        // Export region corresponding to brightness
        // rectangle. Later code uses this to 
        // determine if a specified point is within
        // the region, using the IsVisible method.
        brightnessRegion = new Region(path);

        // Set the location for the brightness indicator "marker".
        // Also calculate the scaling factor, scaling the height
        // to be between 0 and 255. 
        brightnessX = brightnessRectangle.Left + brightnessRectangle.Width;
        brightnessScaling = (double)255 / (brightnessMax - brightnessMin);

        // Calculate the location of the brightness
        // pointer. Assume it's at the highest position.
        brightnessPoint = new Point(brightnessX, brightnessMax);


        // set the range for the alpha selector.
        this.alphaMin = this.alphaRectangle.Top;
        this.alphaMax = this.alphaRectangle.Bottom;

        // Export a region corresponding to the
        // alpha rectangle, with a little extra 
        // "breathing room". 

        path.AddRectangle(new Rectangle(alphaRectangle.Left, alphaRectangle.Top - 10, alphaRectangle.Width + 10, alphaRectangle.Height + 20));
        // Export region corresponding to alpha
        // rectangle. Later code uses this to 
        // determine if a specified point is within
        // the region, using the IsVisible method.
        alphaRegion = new Region(path);

        // Set the location for the alpha indicator "marker".
        // Also calculate the scaling factor, scaling the height
        // to be between 0 and 255. 
        alphaX = alphaRectangle.Left + alphaRectangle.Width;
        alphaScaling = (double)255 / (alphaMax - alphaMin);

        // Calculate the location of the alpha
        // pointer. Assume it's at the highest position.
        alphaPoint = new Point(alphaX, alphaMax);


        // Export the bitmap that contains the circular gradient.
        CreateGradient();
      }
    }

    protected void OnColorChanged(ColorHandler.ARGB RGB, ColorHandler.AHSV AHSV)
    {
      ColorChangedEventArgs e = new ColorChangedEventArgs(RGB, AHSV);
      ColorChanged(this, e);
    }

    public Color Color
    {
      get
      {
        return selectedColor;
      }
    }

    void IDisposable.Dispose()
    {
      // Dispose of graphic resources
      if (colorImage != null)
        colorImage.Dispose();
      if (colorRegion != null)
        colorRegion.Dispose();
      if (brightnessRegion != null)
        brightnessRegion.Dispose();
      if (alphaRegion != null)
        alphaRegion.Dispose();
      if (g != null)
        g.Dispose();
    }

    public void SetMouseUp()
    {
      // Indicate that the user has
      // released the mouse.
      currentState = MouseState.MouseUp;
    }

    public void Draw(Graphics g, ColorHandler.AHSV AHSV)
    {
      // Given AHSV values, update the screen.
      this.g = g;
      this.AHSV = AHSV;
      CalcCoordsAndUpdate(this.AHSV);
      UpdateDisplay();
    }

    public void Draw(Graphics g, ColorHandler.ARGB ARGB)
    {
      // Given RGB values, calculate AHSV and then update the screen.
      this.g = g;
      this.AHSV = ColorHandler.ARGBtoAHSV(ARGB);
      CalcCoordsAndUpdate(this.AHSV);
      UpdateDisplay();
    }

    public void Draw(Graphics g, Point mousePoint)
    {
      // You've moved the mouse. 
      // Now update the screen to match.

      double distance;
      int degrees;
      Point delta;
      Point newColorPoint;
      Point newBrightnessPoint;
      Point newAlphaPoint;
      Point newPoint;

      // Keep track of the previous color pointer point, 
      // so you can put the mouse there in case the 
      // user has clicked outside the circle.
      newColorPoint = colorPoint;
      newBrightnessPoint = brightnessPoint;
      newAlphaPoint = alphaPoint;

      // Store this away for later use.
      this.g = g;

      if (currentState == MouseState.MouseUp)
      {
        if (!mousePoint.IsEmpty)
        {
          if (colorRegion.IsVisible(mousePoint))
          {
            // Is the mouse point within the color circle?
            // If so, you just clicked on the color wheel.
            currentState = MouseState.ClickOnColor;
          }
          else if (brightnessRegion.IsVisible(mousePoint))
          {
            // Is the mouse point within the brightness area?
            // You clicked on the brightness area.
            currentState = MouseState.ClickOnBrightness;
          }
          else if (alphaRegion.IsVisible(mousePoint))
          {
            // Is the mouse point within the alpha area?
            // You clicked on the alpha area.
            currentState = MouseState.ClickOnAlpha;
          }
          else
          {
            // Clicked outside the color, brightness and alpha 
            // regions. In that case, just put the 
            // pointers back where they were.
            currentState = MouseState.ClickOutsideRegion;
          }
        }
      }

      switch (currentState)
      {
        case MouseState.ClickOnBrightness:
        case MouseState.DragInBrightness:
          // Calculate new color information
          // based on the brightness, which may have changed.
          newPoint = mousePoint;
          if (newPoint.Y < brightnessMin)
          {
            newPoint.Y = brightnessMin;
          }
          else if (newPoint.Y > brightnessMax)
          {
            newPoint.Y = brightnessMax;
          }
          newBrightnessPoint = new Point(brightnessX, newPoint.Y);
          brightness = (int)((brightnessMax - newPoint.Y) * brightnessScaling);
          AHSV.Value = brightness;
          ARGB = ColorHandler.AHSVtoARGB(AHSV);
          break;

        case MouseState.ClickOnAlpha:
        case MouseState.DragInAlpha:
          // Calculate new color information
          // based on the alpha, which may have changed.
          newPoint = mousePoint;
          if (newPoint.Y < alphaMin)
          {
            newPoint.Y = alphaMin;
          }
          else if (newPoint.Y > alphaMax)
          {
            newPoint.Y = alphaMax;
          }
          newAlphaPoint = new Point(alphaX, newPoint.Y);
          alpha = (int)((alphaMax - newPoint.Y) * alphaScaling);
          AHSV.Alpha = alpha;
          ARGB = ColorHandler.AHSVtoARGB(AHSV);
          break;

        case MouseState.ClickOnColor:
        case MouseState.DragInColor:
          // Calculate new color information
          // based on selected color, which may have changed.
          newColorPoint = mousePoint;

          // Calculate x and y distance from the center,
          // and then calculate the angle corresponding to the
          // new location.
          delta = new Point(
            mousePoint.X - centerPoint.X, mousePoint.Y - centerPoint.Y);
          degrees = CalcDegrees(delta);

          // Calculate distance from the center to the new point 
          // as a fraction of the radius. Use your old friend, 
          // the Pythagorean theorem, to calculate this value.
          distance = Math.Sqrt(delta.X * delta.X + delta.Y * delta.Y) / radius;

          if (currentState == MouseState.DragInColor)
          {
            if (distance > 1)
            {
              // Mouse is down, and outside the circle, but you 
              // were previously dragging in the color circle. 
              // What to do?
              // In that case, move the point to the edge of the 
              // circle at the correct angle.
              distance = 1;
              newColorPoint = GetPoint(degrees, radius, centerPoint);
            }
          }

          // Calculate the new AHSV and RGB values.
          AHSV.Hue = (int)(degrees * 255 / 360);
          AHSV.Saturation = (int)(distance * 255);
          AHSV.Value = brightness;
          ARGB = ColorHandler.AHSVtoARGB(AHSV);
          fullColor = ColorHandler.AHSVtoColor(AHSV.Alpha, AHSV.Hue, AHSV.Saturation, 255);
          break;
      }
      selectedColor = ColorHandler.AHSVtoColor(AHSV);

      // Raise an event back to the parent form,
      // so the form can update any UI it's using 
      // to display selected color values.
      OnColorChanged(ARGB, AHSV);

      // On the way out, set the new state.
      switch (currentState)
      {
        case MouseState.ClickOnBrightness:
          currentState = MouseState.DragInBrightness;
          break;
        case MouseState.ClickOnAlpha:
          currentState = MouseState.DragInAlpha;
          break;
        case MouseState.ClickOnColor:
          currentState = MouseState.DragInColor;
          break;
        case MouseState.ClickOutsideRegion:
          currentState = MouseState.DragOutsideRegion;
          break;
      }

      // Store away the current points for next time.
      colorPoint = newColorPoint;
      brightnessPoint = newBrightnessPoint;
      alphaPoint = newAlphaPoint;

      // Draw the gradients and points. 
      UpdateDisplay();
    }

    private Point CalcBrightnessPoint(int brightness)
    {
      // Take the value for brightness (0 to 255), scale to the 
      // scaling used in the brightness bar, then add the value 
      // to the bottom of the bar. return the correct point at which 
      // to display the brightness pointer.
      return new Point(brightnessX,
        (int)(brightnessMax - brightness / brightnessScaling));
    }

    private Point CalcAlphaPoint(int alpha)
    {
      // Take the value for alpha (0 to 255), scale to the 
      // scaling used in the alpha bar, then add the value 
      // to the bottom of the bar. return the correct point at which 
      // to display the alpha pointer.
      return new Point(alphaX,
        (int)(alphaMax - alpha / alphaScaling));
    }

    private void UpdateDisplay()
    {
      // Update the gradients, and place the 
      // pointers correctly based on colors and 
      // brightness.

      using (Brush selectedBrush = new SolidBrush(selectedColor))
      {
        // Draw the saved color wheel image.
        g.DrawImage(colorImage, colorRectangle);

        // Draw the "selected color" rectangle.
        DrawSelectedColorRectangle(selectedBrush);

        // Draw the "brightness" rectangle.
        DrawBrightnessLinearGradient(fullColor);

        // Draw the "alpha" rectangle.
        DrawAlphaLinearGradient(selectedColor);

        // Draw the three pointers.
        DrawColorPointer(colorPoint);
        DrawBrightnessPointer(brightnessPoint);
        DrawAlphaPointer(alphaPoint);
      }
    }

    private void CalcCoordsAndUpdate(ColorHandler.AHSV AHSV)
    {
      // Convert color to real-world coordinates and then calculate
      // the various points. AHSV.Hue represents the degrees (0 to 360), 
      // AHSV.Saturation represents the radius. 
      // This procedure doesn't draw anything--it simply 
      // updates class-level variables. The UpdateDisplay
      // procedure uses these values to update the screen.

      // Given the angle (AHSV.Hue), and distance from 
      // the center (AHSV.Saturation), and the center, 
      // calculate the point corresponding to 
      // the selected color, on the color wheel.
      colorPoint = GetPoint((double)AHSV.Hue / 255 * 360,
        (double)AHSV.Saturation / 255 * radius,
        centerPoint);

      // Given the brightness (AHSV.value), calculate the 
      // point corresponding to the brightness indicator.
      brightnessPoint = CalcBrightnessPoint(AHSV.Value);

      // Store information about the selected color.
      brightness = AHSV.Value;
      selectedColor = ColorHandler.AHSVtoColor(AHSV);
      ARGB = ColorHandler.AHSVtoARGB(AHSV);

      // The full color is the same as AHSV, except that the 
      // brightness is set to full (255). This is the top-most
      // color in the brightness gradient.
      fullColor = ColorHandler.AHSVtoColor(AHSV.Alpha, AHSV.Hue, AHSV.Saturation, 255);

      // Given the brightness (AHSV.value), calculate the 
      // point corresponding to the alpha indicator.
      alphaPoint = CalcAlphaPoint(AHSV.Alpha);

      // Store information about the selected color.
      alpha = AHSV.Alpha;

    }

    private void DrawSelectedColorRectangle(Brush brush)
    {
      // Make checkerboard boxes as a background
      int x = selectedColorRectangle.Left;
      int y = selectedColorRectangle.Top;
      int size = 8;
      int brushIndex = 0;
      int rowIndex = 0;
      SolidBrush[] checkerboardBrushes = new SolidBrush[] { (SolidBrush)Brushes.LightGray, (SolidBrush)Brushes.White };
      while (y <= selectedColorRectangle.Bottom)
      {
        while (x <= selectedColorRectangle.Right)
        {
          g.FillRectangle(checkerboardBrushes[brushIndex], x, y, Math.Min(size, selectedColorRectangle.Right - x), Math.Min(size, selectedColorRectangle.Bottom - y));
          x += size;
          brushIndex = (brushIndex + 1) % 2;
        }
        x = selectedColorRectangle.Left;
        rowIndex += 1;
        brushIndex = rowIndex % 2;
        y += size;
      }
      g.FillRectangle(brush, selectedColorRectangle);
    }

    private void DrawBrightnessLinearGradient(Color TopColor)
    {
      // Given the top color, draw a linear gradient
      // ranging from black to the top opaque color. Use the 
      // brightness rectangle as the area to fill.
      TopColor = Color.FromArgb(255, TopColor);
      using (LinearGradientBrush lgb =
               new LinearGradientBrush(brightnessRectangle, TopColor,
               Color.Black, LinearGradientMode.Vertical))
      {
        g.FillRectangle(lgb, brightnessRectangle);
      }
    }

    private void DrawAlphaLinearGradient(Color color)
    {
      // Make checkerboard boxes as a background
      int x = alphaRectangle.Left;
      int y = alphaRectangle.Top;
      int size = 8;
      int brushIndex = 0;
      int rowIndex = 0;
      SolidBrush[] checkerboardBrushes = new SolidBrush[] { (SolidBrush)Brushes.LightGray, (SolidBrush)Brushes.White };
      while (y <= alphaRectangle.Bottom)
      {
        while (x <= alphaRectangle.Right)
        {
          g.FillRectangle(checkerboardBrushes[brushIndex], x, y, Math.Min(size, alphaRectangle.Right - x), Math.Min(size, alphaRectangle.Bottom - y));
          x += size;
          brushIndex = (brushIndex + 1) % 2;
        }
        x = alphaRectangle.Left;
        rowIndex += 1;
        brushIndex = rowIndex % 2;
        y += size;
      }
      foreach (SolidBrush b in checkerboardBrushes)
      {
        b.Dispose();
      }

      // Given the color, draw a linear gradient
      // ranging from opaque to transparent. Use the 
      // alpha rectangle as the area to fill.
      using (LinearGradientBrush lgb =
               new LinearGradientBrush(alphaRectangle, Color.FromArgb(255, color),
               Color.FromArgb(0, color), LinearGradientMode.Vertical))
      {
        g.FillRectangle(lgb, alphaRectangle);
      }
    }

    private int CalcDegrees(Point pt)
    {
      int degrees;

      if (pt.X == 0)
      {
        // The point is on the y-axis. Determine whether 
        // it's above or below the x-axis, and return the 
        // corresponding angle. Note that the orientation of the
        // y-coordinate is backwards. That is, A positive Y value 
        // indicates a point BELOW the x-axis.
        if (pt.Y > 0)
        {
          degrees = 270;
        }
        else
        {
          degrees = 90;
        }
      }
      else
      {
        // This value needs to be multiplied
        // by -1 because the y-coordinate
        // is opposite from the normal direction here.
        // That is, a y-coordinate that's "higher" on 
        // the form has a lower y-value, in this coordinate
        // system. So everything's off by a factor of -1 when
        // performing the ratio calculations.
        degrees = (int)(-Math.Atan((double)pt.Y / pt.X) * DEGREES_PER_RADIAN);

        // If the x-coordinate of the selected point
        // is to the left of the center of the circle, you 
        // need to add 180 degrees to the angle. ArcTan only
        // gives you a value on the right-hand side of the circle.
        if (pt.X < 0)
        {
          degrees += 180;
        }

        // Ensure that the return value is 
        // between 0 and 360.
        degrees = (degrees + 360) % 360;
      }
      return degrees;
    }

    private void CreateGradient()
    {
      // Export a new PathGradientBrush, supplying
      // an array of points created by calling
      // the GetPoints method.
      using (PathGradientBrush pgb =
        new PathGradientBrush(GetPoints(radius, new Point(radius, radius))))
      {
        // Set the various properties. Note the SurroundColors
        // property, which contains an array of points, 
        // in a one-to-one relationship with the points
        // that created the gradient.
        pgb.CenterColor = Color.White;
        pgb.CenterPoint = new PointF(radius, radius);
        pgb.SurroundColors = GetColors();

        // Export a new bitmap containing
        // the color wheel gradient, so the 
        // code only needs to do all this 
        // work once. Later code uses the bitmap
        // rather than recreating the gradient.
        colorImage = new Bitmap(
          colorRectangle.Width, colorRectangle.Height,
          PixelFormat.Format32bppArgb);

        using (Graphics newGraphics =
                 Graphics.FromImage(colorImage))
        {
          newGraphics.FillEllipse(pgb, 0, 0,
            colorRectangle.Width, colorRectangle.Height);
        }
      }
    }

    private Color[] GetColors()
    {
      // Export an array of COLOR_COUNT
      // colors, looping through all the 
      // hues between 0 and 255, broken
      // into COLOR_COUNT intervals. AHSV is
      // particularly well-suited for this, 
      // because the only value that changes
      // as you create colors is the Hue.
      Color[] Colors = new Color[COLOR_COUNT];

      for (int i = 0; i <= COLOR_COUNT - 1; i++)
        Colors[i] = ColorHandler.AHSVtoColor(255, (int)((double)(i * 255) / COLOR_COUNT), 255, 255);
      return Colors;
    }

    private Point[] GetPoints(double radius, Point centerPoint)
    {
      // Generate the array of points that describe
      // the locations of the COLOR_COUNT colors to be 
      // displayed on the color wheel.
      Point[] Points = new Point[COLOR_COUNT];

      for (int i = 0; i <= COLOR_COUNT - 1; i++)
        Points[i] = GetPoint((double)(i * 360) / COLOR_COUNT, radius, centerPoint);
      return Points;
    }

    private Point GetPoint(double degrees, double radius, Point centerPoint)
    {
      // Given the center of a circle and its radius, along
      // with the angle corresponding to the point, find the coordinates. 
      // In other words, conver  t from polar to rectangular coordinates.
      double radians = degrees / DEGREES_PER_RADIAN;

      return new Point((int)(centerPoint.X + Math.Floor(radius * Math.Cos(radians))),
        (int)(centerPoint.Y - Math.Floor(radius * Math.Sin(radians))));
    }

    private void DrawColorPointer(Point pt)
    {
      // Given a point, draw the color selector. 
      // The constant SIZE represents half
      // the width -- the square will be twice
      // this value in width and height.
      const int SIZE = 3;
      g.DrawRectangle(Pens.Black,
        pt.X - SIZE, pt.Y - SIZE, SIZE * 2, SIZE * 2);
    }

    private void DrawBrightnessPointer(Point pt)
    {
      // Draw a triangle for the 
      // brightness indicator that "points"
      // at the provided point.
      const int HEIGHT = 10;
      const int WIDTH = 7;

      Point[] Points = new Point[3];
      Points[0] = pt;
      Points[1] = new Point(pt.X + WIDTH, pt.Y + HEIGHT / 2);
      Points[2] = new Point(pt.X + WIDTH, pt.Y - HEIGHT / 2);
      g.FillPolygon(Brushes.Black, Points);
    }

    private void DrawAlphaPointer(Point pt)
    {
      // Draw a triangle for the 
      // alpha indicator that "points"
      // at the provided point.
      const int HEIGHT = 10;
      const int WIDTH = 7;

      Point[] Points = new Point[3];
      Points[0] = pt;
      Points[1] = new Point(pt.X + WIDTH, pt.Y + HEIGHT / 2);
      Points[2] = new Point(pt.X + WIDTH, pt.Y - HEIGHT / 2);
      g.FillPolygon(Brushes.Black, Points);
    }
  }

  public class ColorHandler
  {
    // Handle conversions between RGB and HSV    
    // (and Color types, as well).

    public struct ARGB
    {
      // All values are between 0 and 255.
      public int Alpha;
      public int Red;
      public int Green;
      public int Blue;

      public ARGB(int A, int R, int G, int B)
      {
        Alpha = A;
        Red = R;
        Green = G;
        Blue = B;
      }

      public override string ToString()
      {
        return String.Format("({0}, {1}, {2}, {3})", Alpha, Red, Green, Blue);
      }
    }

    public struct AHSV
    {
      // All values are between 0 and 255.
      public int Alpha;
      public int Hue;
      public int Saturation;
      public int Value;

      public AHSV(int A, int H, int S, int V)
      {
        Alpha = A;
        Hue = H;
        Saturation = S;
        Value = V;
      }

      public override string ToString()
      {
        return String.Format("({0}, {1}, {2}, {3})", Alpha, Hue, Saturation, Value);
      }
    }

    public static ARGB AHSVtoARGB(int A, int H, int S, int V)
    {
      // H, S, and V must all be between 0 and 255.
      return AHSVtoARGB(new AHSV(A, H, S, V));
    }

    public static Color AHSVtoColor(AHSV ahsv)
    {
      ARGB ARGB = AHSVtoARGB(ahsv);
      return Color.FromArgb(ARGB.Alpha, ARGB.Red, ARGB.Green, ARGB.Blue);
    }

    public static Color AHSVtoColor(int A, int H, int S, int V)
    {
      return AHSVtoColor(new AHSV(A, H, S, V));
    }

    public static ARGB AHSVtoARGB(AHSV AHSV)
    {
      // HSV contains values scaled as in the color wheel:
      // that is, all from 0 to 255. 

      // for ( this code to work, HSV.Hue needs
      // to be scaled from 0 to 360 (it//s the angle of the selected
      // point within the circle). HSV.Saturation and HSV.value must be 
      // scaled to be between 0 and 1.

      double h;
      double s;
      double v;

      double r = 0;
      double g = 0;
      double b = 0;

      // Scale Hue to be between 0 and 360. Saturation
      // and value scale to be between 0 and 1.
      h = ((double)AHSV.Hue / 255 * 360) % 360;
      s = (double)AHSV.Saturation / 255;
      v = (double)AHSV.Value / 255;

      if (s == 0)
      {
        // If s is 0, all colors are the same.
        // This is some flavor of gray.
        r = v;
        g = v;
        b = v;
      }
      else
      {
        double p;
        double q;
        double t;

        double fractionalSector;
        int sectorNumber;
        double sectorPos;

        // The color wheel consists of 6 sectors.
        // Figure out which sector you//re in.
        sectorPos = h / 60;
        sectorNumber = (int)(Math.Floor(sectorPos));

        // get the fractional part of the sector.
        // That is, how many degrees into the sector
        // are you?
        fractionalSector = sectorPos - sectorNumber;

        // Calculate values for the three axes
        // of the color. 
        p = v * (1 - s);
        q = v * (1 - (s * fractionalSector));
        t = v * (1 - (s * (1 - fractionalSector)));

        // Assign the fractional colors to r, g, and b
        // based on the sector the angle is in.
        switch (sectorNumber)
        {
          case 0:
            r = v;
            g = t;
            b = p;
            break;

          case 1:
            r = q;
            g = v;
            b = p;
            break;

          case 2:
            r = p;
            g = v;
            b = t;
            break;

          case 3:
            r = p;
            g = q;
            b = v;
            break;

          case 4:
            r = t;
            g = p;
            b = v;
            break;

          case 5:
            r = v;
            g = p;
            b = q;
            break;
        }
      }
      // return an RGB structure, with values scaled
      // to be between 0 and 255.
      return new ARGB(AHSV.Alpha, (int)(r * 255), (int)(g * 255), (int)(b * 255));
    }

    public static AHSV ARGBtoAHSV(ARGB ARGB)
    {
      // In this function, R, G, and B values must be scaled 
      // to be between 0 and 1.
      // HSV.Hue will be a value between 0 and 360, and 
      // HSV.Saturation and value are between 0 and 1.
      // The code must scale these to be between 0 and 255 for
      // the purposes of this application.

      double min;
      double max;
      double delta;

      double r = (double)ARGB.Red / 255;
      double g = (double)ARGB.Green / 255;
      double b = (double)ARGB.Blue / 255;

      double h;
      double s;
      double v;

      min = Math.Min(Math.Min(r, g), b);
      max = Math.Max(Math.Max(r, g), b);
      v = max;
      delta = max - min;
      if (max == 0 || delta == 0)
      {
        // R, G, and B must be 0, or all the same.
        // In this case, S is 0, and H is undefined.
        // Using H = 0 is as good as any...
        s = 0;
        h = 0;
      }
      else
      {
        s = delta / max;
        if (r == max)
        {
          // Between Yellow and Magenta
          h = (g - b) / delta;
        }
        else if (g == max)
        {
          // Between Cyan and Yellow
          h = 2 + (b - r) / delta;
        }
        else
        {
          // Between Magenta and Cyan
          h = 4 + (r - g) / delta;
        }

      }
      // Scale h to be between 0 and 360. 
      // This may require adding 360, if the value
      // is negative.
      h *= 60;
      if (h < 0)
      {
        h += 360;
      }

      // Scale to the requirements of this 
      // application. All values are between 0 and 255.
      return new AHSV(ARGB.Alpha, (int)(h / 360 * 255), (int)(s * 255), (int)(v * 255));
    }
  }

  public class ColorChangedEventArgs : EventArgs
  {

    private ColorHandler.ARGB mRGB;
    private ColorHandler.AHSV mHSV;

    public ColorChangedEventArgs(ColorHandler.ARGB RGB, ColorHandler.AHSV HSV)
    {
      mRGB = RGB;
      mHSV = HSV;
    }

    public ColorHandler.ARGB ARGB
    {
      get
      {
        return mRGB;
      }
    }

    public ColorHandler.AHSV AHSV
    {
      get
      {
        return mHSV;
      }
    }
  }
}