File: ThemeVisualStyles.cs

package info (click to toggle)
mono-reference-assemblies 3.12.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 604,240 kB
  • ctags: 625,505
  • sloc: cs: 3,967,741; xml: 2,793,081; ansic: 418,042; java: 60,435; sh: 14,833; makefile: 11,576; sql: 7,956; perl: 1,467; cpp: 1,446; yacc: 1,203; python: 598; asm: 422; sed: 16; php: 1
file content (2160 lines) | stat: -rw-r--r-- 87,908 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
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2008 George Giolfan
// Copyright (c) 2004-2006 Novell, Inc.
//
// Authors:
//	George Giolfan, georgegiolfan@yahoo.com
//	Ernesto Carrea, equistango@gmail.com

using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms.VisualStyles;

namespace System.Windows.Forms
{
	/// <summary>
	/// VisualStyles theme.
	/// </summary>
	/// <remarks>
	/// This theme uses only the managed VisualStyles API.
	/// To select it, set MONO_THEME to VisualStyles and call <see cref="Application.EnableVisualStyles"/>.
	/// </remarks>
	class ThemeVisualStyles : ThemeWin32Classic
	{
		static bool render_client_areas;
		static bool render_non_client_areas;

		public ThemeVisualStyles ()
		{
			Update ();
		}

		public override void ResetDefaults ()
		{
			base.ResetDefaults ();
			Update ();
		}

		static void Update ()
		{
			bool visual_styles_is_enabled_by_user = VisualStyleInformation.IsEnabledByUser;
			render_client_areas =
				visual_styles_is_enabled_by_user &&
				(Application.VisualStyleState == VisualStyleState.ClientAndNonClientAreasEnabled ||
				Application.VisualStyleState == VisualStyleState.ClientAreaEnabled);
			render_non_client_areas =
				visual_styles_is_enabled_by_user &&
				(Application.VisualStyleState == VisualStyleState.ClientAndNonClientAreasEnabled/* ||
				Application.VisualStyleState == VisualStyleState.NonClientAreaEnabled*/);
		}

		public static bool RenderClientAreas {
			get { return render_client_areas; }
		}

		#region Controls
		#region ButtonBase
		public override void DrawButtonBase (Graphics dc, Rectangle clip_area, ButtonBase button)
		{
			if (button.FlatStyle == FlatStyle.System) {
				ButtonRenderer.DrawButton (
					dc,
					new Rectangle (Point.Empty, button.Size),
					button.Text,
					button.Font,
					button.TextFormatFlags,
					null,
					Rectangle.Empty,
					ShouldPaintFocusRectagle (button),
					GetPushButtonState (button)
				);
				return;
			}
			base.DrawButtonBase (dc, clip_area, button);
		}
		static PushButtonState GetPushButtonState (ButtonBase button)
		{
			if (!button.Enabled)
				return PushButtonState.Disabled;
			if (button.Pressed)
				return PushButtonState.Pressed;
			if (button.Entered)
				return PushButtonState.Hot;
			if (button.IsDefault || button.Focused || button.paint_as_acceptbutton)
				return PushButtonState.Default;
			return PushButtonState.Normal;
		}
		#endregion

		#region Button 2.0
		public override void DrawButtonBackground (Graphics g, Button button, Rectangle clipArea)
		{
			if (!RenderClientAreas ||
				!button.UseVisualStyleBackColor) {
				base.DrawButtonBackground (g, button, clipArea);
				return;
			}
			ButtonRenderer.GetPushButtonRenderer (GetPushButtonState (button)).DrawBackground (g, new Rectangle (Point.Empty, button.Size));
		}
		#endregion

		#region CheckBox
		protected override void CheckBox_DrawCheckBox (Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle)
		{
			if (checkbox.Appearance == Appearance.Normal && checkbox.FlatStyle == FlatStyle.System) {
				CheckBoxRenderer.DrawCheckBox (
					dc,
					new Point (checkbox_rectangle.Left, checkbox_rectangle.Top),
					GetCheckBoxState (checkbox)
				);
				return;
			}
			base.CheckBox_DrawCheckBox(dc, checkbox, state, checkbox_rectangle);
		}
		static CheckBoxState GetCheckBoxState (CheckBox checkBox)
		{
			switch (checkBox.CheckState) {
			case CheckState.Checked:
				if (!checkBox.Enabled)
					return CheckBoxState.CheckedDisabled;
				else if (checkBox.Pressed)
					return CheckBoxState.CheckedPressed;
				else if (checkBox.Entered)
					return CheckBoxState.CheckedHot;
				return CheckBoxState.CheckedNormal;
			case CheckState.Indeterminate:
				if (!checkBox.Enabled)
					return CheckBoxState.MixedDisabled;
				else if (checkBox.Pressed)
					return CheckBoxState.MixedPressed;
				else if (checkBox.Entered)
					return CheckBoxState.MixedHot;
				return CheckBoxState.MixedNormal;
			default:
				if (!checkBox.Enabled)
					return CheckBoxState.UncheckedDisabled;
				else if (checkBox.Pressed)
					return CheckBoxState.UncheckedPressed;
				else if (checkBox.Entered)
					return CheckBoxState.UncheckedHot;
				return CheckBoxState.UncheckedNormal;
			}
		}
		#endregion
		#region ComboBox
		static VisualStyleElement ComboBoxGetVisualStyleElement (ComboBox comboBox, ButtonState state)
		{
			if (state == ButtonState.Inactive)
				return VisualStyleElement.ComboBox.DropDownButton.Disabled;
			if (state == ButtonState.Pushed)
				return VisualStyleElement.ComboBox.DropDownButton.Pressed;
			if (comboBox.DropDownButtonEntered)
				return VisualStyleElement.ComboBox.DropDownButton.Hot;
			return VisualStyleElement.ComboBox.DropDownButton.Normal;
		}
		public override void ComboBoxDrawNormalDropDownButton (ComboBox comboBox, Graphics g, Rectangle clippingArea, Rectangle area, ButtonState state)
		{
			if (!RenderClientAreas) {
				base.ComboBoxDrawNormalDropDownButton (comboBox, g, clippingArea, area, state);
				return;
			}
			VisualStyleElement element = ComboBoxGetVisualStyleElement (comboBox, state);
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.ComboBoxDrawNormalDropDownButton (comboBox, g, clippingArea, area, state);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (g, area, clippingArea);
		}
		public override bool ComboBoxNormalDropDownButtonHasTransparentBackground (ComboBox comboBox, ButtonState state)
		{
			if (!RenderClientAreas)
				return base.ComboBoxNormalDropDownButtonHasTransparentBackground (comboBox, state);
			VisualStyleElement element = ComboBoxGetVisualStyleElement (comboBox, state);
			if (!VisualStyleRenderer.IsElementDefined (element))
				return base.ComboBoxNormalDropDownButtonHasTransparentBackground (comboBox, state);
			return new VisualStyleRenderer (element).IsBackgroundPartiallyTransparent ();
		}
		public override bool ComboBoxDropDownButtonHasHotElementStyle (ComboBox comboBox)
		{
			if (!RenderClientAreas)
				return base.ComboBoxDropDownButtonHasHotElementStyle (comboBox);
			switch (comboBox.FlatStyle) {
			case FlatStyle.Flat:
			case FlatStyle.Popup:
				return base.ComboBoxDropDownButtonHasHotElementStyle (comboBox);
			}
			return true;
		}
		static bool ComboBoxShouldPaintBackground (ComboBox comboBox)
		{
			if (comboBox.DropDownStyle == ComboBoxStyle.Simple)
				return false;
			switch (comboBox.FlatStyle) {
			case FlatStyle.Flat:
			case FlatStyle.Popup:
				return false;
			}
			return true;
		}
		public override void ComboBoxDrawBackground (ComboBox comboBox, Graphics g, Rectangle clippingArea, FlatStyle style)
		{
			if (!RenderClientAreas || !ComboBoxShouldPaintBackground (comboBox)) {
				base.ComboBoxDrawBackground (comboBox, g, clippingArea, style);
				return;
			}
			VisualStyleElement element;
			if (!comboBox.Enabled)
				element = VisualStyleElement.ComboBox.Border.Disabled;
			else if (comboBox.Entered)
				element = VisualStyleElement.ComboBox.Border.Hot;
			else if (comboBox.Focused)
				element = VisualStyleElement.ComboBox.Border.Focused;
			else
				element = VisualStyleElement.ComboBox.Border.Normal;
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.ComboBoxDrawBackground (comboBox, g, clippingArea, style);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (g, new Rectangle (Point.Empty, comboBox.Size), clippingArea);
		}
		public override bool CombBoxBackgroundHasHotElementStyle (ComboBox comboBox)
		{
			if (RenderClientAreas &&
				ComboBoxShouldPaintBackground (comboBox) &&
				comboBox.Enabled &&
				VisualStyleRenderer.IsElementDefined (VisualStyleElement.ComboBox.Border.Hot))
				return true;
			return base.CombBoxBackgroundHasHotElementStyle (comboBox);
		}
		#endregion
		#region ControlPaint
		#region DrawButton
		public override void CPDrawButton (Graphics dc, Rectangle rectangle, ButtonState state)
		{
			if (!RenderClientAreas ||
				(state & ButtonState.Flat) == ButtonState.Flat ||
				(state & ButtonState.Checked) == ButtonState.Checked) {
				base.CPDrawButton (dc, rectangle, state);
				return;
			}
			VisualStyleElement element;
			if ((state & ButtonState.Inactive) == ButtonState.Inactive)
				element = VisualStyleElement.Button.PushButton.Disabled;
			else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
				element = VisualStyleElement.Button.PushButton.Pressed;
			else
				element = VisualStyleElement.Button.PushButton.Normal;
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.CPDrawButton (dc, rectangle, state);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
		}
		#endregion
		#region DrawCaptionButton
		public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state)
		{
			if (!RenderClientAreas ||
				(state & ButtonState.Flat) == ButtonState.Flat ||
				(state & ButtonState.Checked) == ButtonState.Checked) {
				base.CPDrawCaptionButton (graphics, rectangle, button, state);
				return;
			}
			VisualStyleElement element = GetCaptionButtonVisualStyleElement (button, state);
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.CPDrawCaptionButton (graphics, rectangle, button, state);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (graphics, rectangle);
		}
		static VisualStyleElement GetCaptionButtonVisualStyleElement (CaptionButton button, ButtonState state)
		{
			switch (button) {
			case CaptionButton.Minimize:
				if ((state & ButtonState.Inactive) == ButtonState.Inactive)
					return VisualStyleElement.Window.MinButton.Disabled;
				else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
					return VisualStyleElement.Window.MinButton.Pressed;
				else
					return VisualStyleElement.Window.MinButton.Normal;
			case CaptionButton.Maximize:
				if ((state & ButtonState.Inactive) == ButtonState.Inactive)
					return VisualStyleElement.Window.MaxButton.Disabled;
				else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
					return VisualStyleElement.Window.MaxButton.Pressed;
				else
					return VisualStyleElement.Window.MaxButton.Normal;
			case CaptionButton.Close:
				if ((state & ButtonState.Inactive) == ButtonState.Inactive)
					return VisualStyleElement.Window.CloseButton.Disabled;
				else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
					return VisualStyleElement.Window.CloseButton.Pressed;
				else
					return VisualStyleElement.Window.CloseButton.Normal;
			case CaptionButton.Restore:
				if ((state & ButtonState.Inactive) == ButtonState.Inactive)
					return VisualStyleElement.Window.RestoreButton.Disabled;
				else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
					return VisualStyleElement.Window.RestoreButton.Pressed;
				else
					return VisualStyleElement.Window.RestoreButton.Normal;
			default:
				if ((state & ButtonState.Inactive) == ButtonState.Inactive)
					return VisualStyleElement.Window.HelpButton.Disabled;
				else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
					return VisualStyleElement.Window.HelpButton.Pressed;
				else
					return VisualStyleElement.Window.HelpButton.Normal;
			}
		}
		#endregion
		#region DrawCheckBox
		public override void CPDrawCheckBox (Graphics dc, Rectangle rectangle, ButtonState state)
		{
			if (!RenderClientAreas ||
				(state & ButtonState.Flat) == ButtonState.Flat) {
				base.CPDrawCheckBox (dc, rectangle, state);
				return;
			}
			VisualStyleElement element;
			if ((state & ButtonState.Checked) == ButtonState.Checked)
				if ((state & ButtonState.Inactive) == ButtonState.Inactive)
					element = VisualStyleElement.Button.CheckBox.CheckedDisabled;
				else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
					element = VisualStyleElement.Button.CheckBox.CheckedPressed;
				else
					element = VisualStyleElement.Button.CheckBox.CheckedNormal;
			else
				if ((state & ButtonState.Inactive) == ButtonState.Inactive)
					element = VisualStyleElement.Button.CheckBox.UncheckedDisabled;
				else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
					element = VisualStyleElement.Button.CheckBox.UncheckedPressed;
				else
					element = VisualStyleElement.Button.CheckBox.UncheckedNormal;
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.CPDrawCheckBox (dc, rectangle, state);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
		}
		#endregion
		#region DrawComboButton
		public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state)
		{
			if (!RenderClientAreas ||
				(state & ButtonState.Flat) == ButtonState.Flat ||
				(state & ButtonState.Checked) == ButtonState.Checked) {
				base.CPDrawComboButton (graphics, rectangle, state);
				return;
			}
			VisualStyleElement element;
			if ((state & ButtonState.Inactive) == ButtonState.Inactive)
				element = VisualStyleElement.ComboBox.DropDownButton.Disabled;
			else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
				element = VisualStyleElement.ComboBox.DropDownButton.Pressed;
			else
				element = VisualStyleElement.ComboBox.DropDownButton.Normal;
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.CPDrawComboButton (graphics, rectangle, state);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (graphics, rectangle);
		}
		#endregion
		#region DrawMixedCheckBox
		public override void CPDrawMixedCheckBox (Graphics dc, Rectangle rectangle, ButtonState state)
		{
			if (!RenderClientAreas ||
				(state & ButtonState.Flat) == ButtonState.Flat) {
				base.CPDrawMixedCheckBox (dc, rectangle, state);
				return;
			}
			VisualStyleElement element;
			if ((state & ButtonState.Checked) == ButtonState.Checked)
				if ((state & ButtonState.Inactive) == ButtonState.Inactive)
					element = VisualStyleElement.Button.CheckBox.MixedDisabled;
				else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
					element = VisualStyleElement.Button.CheckBox.MixedPressed;
				else
					element = VisualStyleElement.Button.CheckBox.MixedNormal;
			else
				if ((state & ButtonState.Inactive) == ButtonState.Inactive)
					element = VisualStyleElement.Button.CheckBox.UncheckedDisabled;
				else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
					element = VisualStyleElement.Button.CheckBox.UncheckedPressed;
				else
					element = VisualStyleElement.Button.CheckBox.UncheckedNormal;
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.CPDrawMixedCheckBox (dc, rectangle, state);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
		}
		#endregion
		#region DrawRadioButton
		public override void CPDrawRadioButton (Graphics dc, Rectangle rectangle, ButtonState state)
		{
			if (!RenderClientAreas ||
				(state & ButtonState.Flat) == ButtonState.Flat) {
				base.CPDrawRadioButton (dc, rectangle, state);
				return;
			}
			VisualStyleElement element;
			if ((state & ButtonState.Checked) == ButtonState.Checked)
				if ((state & ButtonState.Inactive) == ButtonState.Inactive)
					element = VisualStyleElement.Button.RadioButton.CheckedDisabled;
				else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
					element = VisualStyleElement.Button.RadioButton.CheckedPressed;
				else
					element = VisualStyleElement.Button.RadioButton.CheckedNormal;
			else
				if ((state & ButtonState.Inactive) == ButtonState.Inactive)
					element = VisualStyleElement.Button.RadioButton.UncheckedDisabled;
				else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
					element = VisualStyleElement.Button.RadioButton.UncheckedPressed;
				else
					element = VisualStyleElement.Button.RadioButton.UncheckedNormal;
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.CPDrawRadioButton (dc, rectangle, state);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
		}
		#endregion
		#region DrawScrollButton
		public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state)
		{
			if (!RenderClientAreas ||
				(state & ButtonState.Flat) == ButtonState.Flat ||
				(state & ButtonState.Checked) == ButtonState.Checked) {
				base.CPDrawScrollButton (dc, area, type, state);
				return;
			}
			VisualStyleElement element = GetScrollButtonVisualStyleElement (type, state);
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.CPDrawScrollButton (dc, area, type, state);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (dc, area);
		}
		static VisualStyleElement GetScrollButtonVisualStyleElement (ScrollButton type, ButtonState state)
		{
			switch (type) {
			case ScrollButton.Left:
				if (IsDisabled (state))
					return VisualStyleElement.ScrollBar.ArrowButton.LeftDisabled;
				else if (IsPressed (state))
					return VisualStyleElement.ScrollBar.ArrowButton.LeftPressed;
				else
					return VisualStyleElement.ScrollBar.ArrowButton.LeftNormal;
			case ScrollButton.Right:
				if (IsDisabled (state))
					return VisualStyleElement.ScrollBar.ArrowButton.RightDisabled;
				else if (IsPressed (state))
					return VisualStyleElement.ScrollBar.ArrowButton.RightPressed;
				else
					return VisualStyleElement.ScrollBar.ArrowButton.RightNormal;
			case ScrollButton.Up:
				if (IsDisabled (state))
					return VisualStyleElement.ScrollBar.ArrowButton.UpDisabled;
				else if (IsPressed (state))
					return VisualStyleElement.ScrollBar.ArrowButton.UpPressed;
				else
					return VisualStyleElement.ScrollBar.ArrowButton.UpNormal;
			default:
				if (IsDisabled (state))
					return VisualStyleElement.ScrollBar.ArrowButton.DownDisabled;
				else if (IsPressed (state))
					return VisualStyleElement.ScrollBar.ArrowButton.DownPressed;
				else
					return VisualStyleElement.ScrollBar.ArrowButton.DownNormal;
			}
		}
		static bool IsDisabled (ButtonState state)
		{
			return (state & ButtonState.Inactive) == ButtonState.Inactive;
		}
		static bool IsPressed (ButtonState state)
		{
			return (state & ButtonState.Pushed) == ButtonState.Pushed;
		}
		#endregion
		#endregion

		#region DataGridView
		#region DataGridViewHeaderCell
		#region DataGridViewRowHeaderCell
		public override bool DataGridViewRowHeaderCellDrawBackground (DataGridViewRowHeaderCell cell, Graphics g, Rectangle bounds)
		{
			if (!RenderClientAreas ||
				!cell.DataGridView.EnableHeadersVisualStyles)
				return base.DataGridViewRowHeaderCellDrawBackground (cell, g, bounds);
			VisualStyleElement element = DataGridViewRowHeaderCellGetVisualStyleElement (cell);
			if (!VisualStyleRenderer.IsElementDefined (element))
				return base.DataGridViewRowHeaderCellDrawBackground (cell, g, bounds);
			bounds.Width--;
			Bitmap bitmap = new Bitmap (bounds.Height, bounds.Width);
			Graphics bitmap_g = Graphics.FromImage (bitmap);
			Rectangle bitmap_rectangle = new Rectangle (Point.Empty, bitmap.Size);
			VisualStyleRenderer renderer = new VisualStyleRenderer (element);
			if (!AreEqual (element, VisualStyleElement.Header.Item.Normal) && renderer.IsBackgroundPartiallyTransparent ())
				new VisualStyleRenderer (VisualStyleElement.Header.Item.Normal).DrawBackground (bitmap_g, bitmap_rectangle);
			renderer.DrawBackground (bitmap_g, bitmap_rectangle);
			bitmap_g.Dispose ();
			g.Transform = new Matrix(0, 1, 1, 0, 0, 0);
			g.DrawImage (bitmap, bounds.Y, bounds.X);
			bitmap.Dispose ();
			g.ResetTransform ();
			return true;
		}
		public override bool DataGridViewRowHeaderCellDrawSelectionBackground (DataGridViewRowHeaderCell cell)
		{
			if (!RenderClientAreas ||
				!cell.DataGridView.EnableHeadersVisualStyles || !VisualStyleRenderer.IsElementDefined (DataGridViewRowHeaderCellGetVisualStyleElement (cell)))
				return base.DataGridViewRowHeaderCellDrawSelectionBackground (cell);
			return true;
		}
		public override bool DataGridViewRowHeaderCellDrawBorder (DataGridViewRowHeaderCell cell, Graphics g, Rectangle bounds)
		{
			if (!RenderClientAreas ||
				!cell.DataGridView.EnableHeadersVisualStyles || !VisualStyleRenderer.IsElementDefined (DataGridViewRowHeaderCellGetVisualStyleElement (cell)))
				return base.DataGridViewRowHeaderCellDrawBorder (cell, g, bounds);
			g.DrawLine (cell.GetBorderPen (), bounds.Right - 1, bounds.Top, bounds.Right - 1, bounds.Bottom - 1);
			return true;
		}
		static VisualStyleElement DataGridViewRowHeaderCellGetVisualStyleElement (DataGridViewRowHeaderCell cell)
		{
			if (cell.DataGridView.PressedHeaderCell == cell)
				return VisualStyleElement.Header.Item.Pressed;
			if (cell.DataGridView.EnteredHeaderCell == cell)
				return VisualStyleElement.Header.Item.Hot;
			if (cell.OwningRow.SelectedInternal)
				return VisualStyleElement.Header.Item.Pressed;
			return VisualStyleElement.Header.Item.Normal;
		}
		#endregion
		#region DataGridViewColumnHeaderCell
		public override bool DataGridViewColumnHeaderCellDrawBackground (DataGridViewColumnHeaderCell cell, Graphics g, Rectangle bounds)
		{
			if (!RenderClientAreas ||
				!cell.DataGridView.EnableHeadersVisualStyles || cell is DataGridViewTopLeftHeaderCell)
				return base.DataGridViewColumnHeaderCellDrawBackground (cell, g, bounds);
			VisualStyleElement element = DataGridViewColumnHeaderCellGetVisualStyleElement (cell);
			if (!VisualStyleRenderer.IsElementDefined (element))
				return base.DataGridViewColumnHeaderCellDrawBackground (cell, g, bounds);
			bounds.Height--;
			VisualStyleRenderer renderer = new VisualStyleRenderer (element);
			if (!AreEqual (element, VisualStyleElement.Header.Item.Normal) && renderer.IsBackgroundPartiallyTransparent ())
			    new VisualStyleRenderer (VisualStyleElement.Header.Item.Normal).DrawBackground (g, bounds);
			renderer.DrawBackground (g, bounds);
			return true;
		}
		public override bool DataGridViewColumnHeaderCellDrawBorder (DataGridViewColumnHeaderCell cell, Graphics g, Rectangle bounds)
		{
			if (!RenderClientAreas ||
				!cell.DataGridView.EnableHeadersVisualStyles ||
				cell is DataGridViewTopLeftHeaderCell ||
				!VisualStyleRenderer.IsElementDefined (VisualStyleElement.Header.Item.Normal))
				return base.DataGridViewColumnHeaderCellDrawBorder (cell, g, bounds);
			g.DrawLine (cell.GetBorderPen (), bounds.Left, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 1);
			return true;
		}
		static VisualStyleElement DataGridViewColumnHeaderCellGetVisualStyleElement (DataGridViewColumnHeaderCell cell)
		{
			if (cell.DataGridView.PressedHeaderCell == cell)
				return VisualStyleElement.Header.Item.Pressed;
			if (cell.DataGridView.EnteredHeaderCell == cell)
				return VisualStyleElement.Header.Item.Hot;
			return VisualStyleElement.Header.Item.Normal;
		}
		#endregion
		public override bool DataGridViewHeaderCellHasPressedStyle (DataGridView dataGridView)
		{
			if (!RenderClientAreas ||
				!dataGridView.EnableHeadersVisualStyles ||
				!VisualStyleRenderer.IsElementDefined (VisualStyleElement.Header.Item.Pressed))
				return base.DataGridViewHeaderCellHasPressedStyle (dataGridView);
			return true;
		}
		public override bool DataGridViewHeaderCellHasHotStyle (DataGridView dataGridView)
		{
			if (!RenderClientAreas ||
				!dataGridView.EnableHeadersVisualStyles ||
				!VisualStyleRenderer.IsElementDefined (VisualStyleElement.Header.Item.Hot))
				return base.DataGridViewHeaderCellHasHotStyle (dataGridView);
			return true;
		}
		#endregion
		#endregion

		#region DateTimePicker
		#region Border
		protected override void DateTimePickerDrawBorder (DateTimePicker dateTimePicker, Graphics g, Rectangle clippingArea)
		{
			if (!RenderClientAreas) {
				base.DateTimePickerDrawBorder (dateTimePicker, g, clippingArea);
				return;
			}
			VisualStyleElement element;
			if (!dateTimePicker.Enabled)
				element = VisualStyleElement.DatePicker.DateBorder.Disabled;
			else if (dateTimePicker.Entered)
				element = VisualStyleElement.DatePicker.DateBorder.Hot;
			else if (dateTimePicker.Focused)
				element = VisualStyleElement.DatePicker.DateBorder.Focused;
			else
				element = VisualStyleElement.DatePicker.DateBorder.Normal;
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.DateTimePickerDrawBorder (dateTimePicker, g, clippingArea);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (g, new Rectangle (Point.Empty, dateTimePicker.Size), clippingArea);
		}
		public override bool DateTimePickerBorderHasHotElementStyle {
			get {
				if (RenderClientAreas &&
					VisualStyleRenderer.IsElementDefined (VisualStyleElement.DatePicker.DateBorder.Hot))
					return true;
				return base.DateTimePickerBorderHasHotElementStyle;
			}
		}
		#endregion
		#region Drop down button
		protected override void DateTimePickerDrawDropDownButton (DateTimePicker dateTimePicker, Graphics g, Rectangle clippingArea)
		{
			if (!RenderClientAreas) {
				base.DateTimePickerDrawDropDownButton (dateTimePicker, g, clippingArea);
				return;
			}
			VisualStyleElement element;
			if (!dateTimePicker.Enabled)
				element = VisualStyleElement.DatePicker.ShowCalendarButtonRight.Disabled;
			else if (dateTimePicker.is_drop_down_visible)
				element = VisualStyleElement.DatePicker.ShowCalendarButtonRight.Pressed;
			else if (dateTimePicker.DropDownButtonEntered)
				element = VisualStyleElement.DatePicker.ShowCalendarButtonRight.Hot;
			else
				element = VisualStyleElement.DatePicker.ShowCalendarButtonRight.Normal;
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.DateTimePickerDrawDropDownButton (dateTimePicker, g, clippingArea);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (g, dateTimePicker.drop_down_arrow_rect, clippingArea);
		}
		//TODO: Until somebody figures out how to obtain the proper width this will need to be updated when new Windows versions/themes are released.
		const int DateTimePickerDropDownWidthOnWindowsVista = 34;
		const int DateTimePickerDropDownHeightOnWindowsVista = 20;
		public override Rectangle DateTimePickerGetDropDownButtonArea (DateTimePicker dateTimePicker)
		{
			if (!RenderClientAreas)
				return base.DateTimePickerGetDropDownButtonArea (dateTimePicker);
			VisualStyleElement element = VisualStyleElement.DatePicker.ShowCalendarButtonRight.Pressed;
			if (!VisualStyleRenderer.IsElementDefined (element))
				return base.DateTimePickerGetDropDownButtonArea (dateTimePicker);
			Size size = new Size (DateTimePickerDropDownWidthOnWindowsVista, DateTimePickerDropDownHeightOnWindowsVista);
			return new Rectangle (dateTimePicker.Width - size.Width, 0, size.Width, size.Height);
		}
		public override Rectangle DateTimePickerGetDateArea (DateTimePicker dateTimePicker)
		{
			if (!RenderClientAreas ||
				dateTimePicker.ShowUpDown)
				return base.DateTimePickerGetDateArea (dateTimePicker);
			VisualStyleElement element = VisualStyleElement.DatePicker.DateBorder.Normal;
			if (!VisualStyleRenderer.IsElementDefined (element))
				return base.DateTimePickerGetDateArea (dateTimePicker);
			Graphics g = dateTimePicker.CreateGraphics ();
			Rectangle result = new VisualStyleRenderer (element).GetBackgroundContentRectangle (g, dateTimePicker.ClientRectangle);
			g.Dispose ();
			result.Width -= DateTimePickerDropDownWidthOnWindowsVista;
			return result;
		}
		public override bool DateTimePickerDropDownButtonHasHotElementStyle {
			get {
				if (RenderClientAreas &&
					VisualStyleRenderer.IsElementDefined (VisualStyleElement.DatePicker.ShowCalendarButtonRight.Hot))
					return true;
				return base.DateTimePickerDropDownButtonHasHotElementStyle;
			}
		}
		#endregion
		#endregion
		#region ListView
		protected override void ListViewDrawColumnHeaderBackground (ListView listView, ColumnHeader columnHeader, Graphics g, Rectangle area, Rectangle clippingArea)
		{
			if (!RenderClientAreas) {
				base.ListViewDrawColumnHeaderBackground (listView, columnHeader, g, area, clippingArea);
				return;
			}
			VisualStyleElement element;
			if (listView.HeaderStyle == ColumnHeaderStyle.Clickable)
				if (columnHeader.Pressed)
					element = VisualStyleElement.Header.Item.Pressed;
				else if (columnHeader == listView.EnteredColumnHeader)
					element = VisualStyleElement.Header.Item.Hot;
				else
					element = VisualStyleElement.Header.Item.Normal;
			else
				element = VisualStyleElement.Header.Item.Normal;
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.ListViewDrawColumnHeaderBackground (listView, columnHeader, g, area, clippingArea);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (g, area, clippingArea);
		}
		protected override void ListViewDrawUnusedHeaderBackground (ListView listView, Graphics g, Rectangle area, Rectangle clippingArea)
		{
			if (!RenderClientAreas) {
				base.ListViewDrawUnusedHeaderBackground (listView, g, area, clippingArea);
				return;
			}
			VisualStyleElement element = VisualStyleElement.Header.Item.Normal;
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.ListViewDrawUnusedHeaderBackground (listView, g, area, clippingArea);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (g, area, clippingArea);
		}
		public override bool ListViewHasHotHeaderStyle {
			get {
				if (!RenderClientAreas ||
					!VisualStyleRenderer.IsElementDefined (VisualStyleElement.Header.Item.Hot))
					return base.ListViewHasHotHeaderStyle;
				return true;
			}
		}
		public override int ListViewGetHeaderHeight (ListView listView, Font font)
		{
			if (!RenderClientAreas)
				return base.ListViewGetHeaderHeight (listView, font);
			VisualStyleElement element = VisualStyleElement.Header.Item.Normal;
			if (!VisualStyleRenderer.IsElementDefined (element))
				return base.ListViewGetHeaderHeight (listView, font);
			Control control = null;
			Graphics g;
			if (listView == null) {
				control = new Control ();
				g = control.CreateGraphics ();
			} else
				g = listView.CreateGraphics ();
			int result = new VisualStyleRenderer (element).GetPartSize (g, ThemeSizeType.True).Height;
			g.Dispose ();
			if (listView == null)
				control.Dispose ();
			return result;
		}
		#endregion
		#region GroupBox
		public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box)
		{
			GroupBoxRenderer.DrawGroupBox (
				dc,
				new Rectangle (Point.Empty, box.Size),
				box.Text,
				box.Font,
				box.ForeColor == GroupBox.DefaultForeColor ? Color.Empty : box.ForeColor,
				box.Enabled ? GroupBoxState.Normal : GroupBoxState.Disabled);
		}
		#endregion
		#region Managed window
		Rectangle ManagedWindowGetTitleBarRectangle (InternalWindowManager wm)
		{
			return new Rectangle (0, 0, wm.Form.Width, ManagedWindowTitleBarHeight (wm) + ManagedWindowBorderWidth (wm) * (wm.IsMinimized ? 2 : 1));
		}
		Region ManagedWindowGetWindowRegion (Form form)
		{
			if (form.WindowManager is MdiWindowManager && form.WindowManager.IsMaximized)
				return null;
			VisualStyleElement title_bar_element = ManagedWindowGetTitleBarVisualStyleElement (form.WindowManager);
			if (!VisualStyleRenderer.IsElementDefined (title_bar_element))
				return null;
			VisualStyleRenderer renderer = new VisualStyleRenderer (title_bar_element);
			if (!renderer.IsBackgroundPartiallyTransparent ())
				return null;
			IDeviceContext dc = GetMeasurementDeviceContext ();
			Rectangle title_bar_rectangle = ManagedWindowGetTitleBarRectangle (form.WindowManager);
			Region region = renderer.GetBackgroundRegion (dc, title_bar_rectangle);
			ReleaseMeasurementDeviceContext (dc);
			region.Union (new Rectangle (0, title_bar_rectangle.Bottom, form.Width, form.Height));
			return region;
		}
		public override void ManagedWindowOnSizeInitializedOrChanged (Form form)
		{
			base.ManagedWindowOnSizeInitializedOrChanged (form);
			if (!render_non_client_areas)
				return;
			form.Region = ManagedWindowGetWindowRegion (form);
		}
		protected override Rectangle ManagedWindowDrawTitleBarAndBorders (Graphics dc, Rectangle clip, InternalWindowManager wm)
		{
			if (!render_non_client_areas)
				return base.ManagedWindowDrawTitleBarAndBorders (dc, clip, wm);
			VisualStyleElement title_bar_element = ManagedWindowGetTitleBarVisualStyleElement (wm);
			VisualStyleElement left_border_element;
			VisualStyleElement right_border_element;
			VisualStyleElement bottom_border_element;
			ManagedWindowGetBorderVisualStyleElements (wm, out left_border_element, out right_border_element, out bottom_border_element);
			if (!VisualStyleRenderer.IsElementDefined (title_bar_element) ||
				(!wm.IsMinimized && (
				!VisualStyleRenderer.IsElementDefined (left_border_element) ||
				!VisualStyleRenderer.IsElementDefined (right_border_element) ||
				!VisualStyleRenderer.IsElementDefined (bottom_border_element))))
				return base.ManagedWindowDrawTitleBarAndBorders (dc, clip, wm);
			VisualStyleRenderer renderer = new VisualStyleRenderer (title_bar_element);
			Rectangle title_bar_rectangle = ManagedWindowGetTitleBarRectangle (wm);
			renderer.DrawBackground (dc, title_bar_rectangle, clip);
			if (!wm.IsMinimized) {
				int border_width = ManagedWindowBorderWidth (wm);
				renderer.SetParameters (left_border_element);
				renderer.DrawBackground (dc, new Rectangle (
					0,
					title_bar_rectangle.Bottom,
					border_width,
					wm.Form.Height - title_bar_rectangle.Bottom
					), clip);
				renderer.SetParameters (right_border_element);
				renderer.DrawBackground (dc, new Rectangle (
					wm.Form.Width - border_width,
					title_bar_rectangle.Bottom,
					border_width,
					wm.Form.Height - title_bar_rectangle.Bottom
					), clip);
				renderer.SetParameters (bottom_border_element);
				renderer.DrawBackground (dc, new Rectangle (
					0,
					wm.Form.Height - border_width,
					wm.Form.Width,
					border_width
					), clip);
			}
			return title_bar_rectangle;
		}
		static FormWindowState ManagedWindowGetWindowState (InternalWindowManager wm)
		{
			return wm.GetWindowState ();
		}
		static bool ManagedWindowIsDisabled (InternalWindowManager wm)
		{
			return !wm.Form.Enabled;
		}
		static bool ManagedWindowIsActive (InternalWindowManager wm)
		{
			return wm.IsActive;
		}
		static VisualStyleElement ManagedWindowGetTitleBarVisualStyleElement (InternalWindowManager wm)
		{
			if (wm.IsToolWindow)
				#region Small window
				switch (ManagedWindowGetWindowState (wm)) {
				case FormWindowState.Minimized:
					if (ManagedWindowIsDisabled (wm))
						return VisualStyleElement.Window.SmallMinCaption.Disabled;
					else if (ManagedWindowIsActive (wm))
						return VisualStyleElement.Window.SmallMinCaption.Active;
					return VisualStyleElement.Window.SmallMinCaption.Inactive;
				case FormWindowState.Maximized:
					if (ManagedWindowIsDisabled (wm))
						return VisualStyleElement.Window.SmallMaxCaption.Disabled;
					else if (ManagedWindowIsActive (wm))
						return VisualStyleElement.Window.SmallMaxCaption.Active;
					return VisualStyleElement.Window.SmallMaxCaption.Inactive;
				default:
					if (ManagedWindowIsDisabled (wm))
						return VisualStyleElement.Window.SmallCaption.Disabled;
					else if (ManagedWindowIsActive (wm))
						return VisualStyleElement.Window.SmallCaption.Active;
					return VisualStyleElement.Window.SmallCaption.Inactive;
				}
				#endregion
			else
				#region Normal window
				switch (ManagedWindowGetWindowState (wm)) {
				case FormWindowState.Minimized:
					if (ManagedWindowIsDisabled (wm))
						return VisualStyleElement.Window.MinCaption.Disabled;
					else if (ManagedWindowIsActive (wm))
						return VisualStyleElement.Window.MinCaption.Active;
					return VisualStyleElement.Window.MinCaption.Inactive;
				case FormWindowState.Maximized:
					if (ManagedWindowIsDisabled (wm))
						return VisualStyleElement.Window.MaxCaption.Disabled;
					else if (ManagedWindowIsActive (wm))
						return VisualStyleElement.Window.MaxCaption.Active;
					return VisualStyleElement.Window.MaxCaption.Inactive;
				default:
					if (ManagedWindowIsDisabled (wm))
						return VisualStyleElement.Window.Caption.Disabled;
					else if (ManagedWindowIsActive (wm))
						return VisualStyleElement.Window.Caption.Active;
					return VisualStyleElement.Window.Caption.Inactive;
				}
				#endregion
		}
		static void ManagedWindowGetBorderVisualStyleElements (InternalWindowManager wm, out VisualStyleElement left, out VisualStyleElement right, out VisualStyleElement bottom)
		{
			bool active = !ManagedWindowIsDisabled (wm) && ManagedWindowIsActive (wm);
			if (wm.IsToolWindow) {
				if (active) {
					left = VisualStyleElement.Window.SmallFrameLeft.Active;
					right = VisualStyleElement.Window.SmallFrameRight.Active;
					bottom = VisualStyleElement.Window.SmallFrameBottom.Active;
				} else {
					left = VisualStyleElement.Window.SmallFrameLeft.Inactive;
					right = VisualStyleElement.Window.SmallFrameRight.Inactive;
					bottom = VisualStyleElement.Window.SmallFrameBottom.Inactive;
				}
			} else {
				if (active) {
					left = VisualStyleElement.Window.FrameLeft.Active;
					right = VisualStyleElement.Window.FrameRight.Active;
					bottom = VisualStyleElement.Window.FrameBottom.Active;
				} else {
					left = VisualStyleElement.Window.FrameLeft.Inactive;
					right = VisualStyleElement.Window.FrameRight.Inactive;
					bottom = VisualStyleElement.Window.FrameBottom.Inactive;
				}
			}
		}
		public override bool ManagedWindowTitleButtonHasHotElementStyle (TitleButton button, Form form)
		{
			if (render_non_client_areas && (button.State & ButtonState.Inactive) != ButtonState.Inactive) {
				VisualStyleElement element;
				if (ManagedWindowIsMaximizedMdiChild (form))
					switch (button.Caption) {
					case CaptionButton.Close:
						element = VisualStyleElement.Window.MdiCloseButton.Hot;
						break;
					case CaptionButton.Help:
						element = VisualStyleElement.Window.MdiHelpButton.Hot;
						break;
					case CaptionButton.Minimize:
						element = VisualStyleElement.Window.MdiMinButton.Hot;
						break;
					default:
						element = VisualStyleElement.Window.MdiRestoreButton.Hot;
						break;
					}
				else if (form.WindowManager.IsToolWindow)
					element = VisualStyleElement.Window.SmallCloseButton.Hot;
				else
					switch (button.Caption) {
					case CaptionButton.Close:
						element = VisualStyleElement.Window.CloseButton.Hot;
						break;
					case CaptionButton.Help:
						element = VisualStyleElement.Window.HelpButton.Hot;
						break;
					case CaptionButton.Maximize:
						element = VisualStyleElement.Window.MaxButton.Hot;
						break;
					case CaptionButton.Minimize:
						element = VisualStyleElement.Window.MinButton.Hot;
						break;
					default:
						element = VisualStyleElement.Window.RestoreButton.Hot;
						break;
					}
				if (VisualStyleRenderer.IsElementDefined (element))
					return true;
			}
			return base.ManagedWindowTitleButtonHasHotElementStyle (button, form);
		}
		static bool ManagedWindowIsMaximizedMdiChild (Form form)
		{
			return form.WindowManager is MdiWindowManager &&
				ManagedWindowGetWindowState (form.WindowManager) == FormWindowState.Maximized;
		}
		static bool ManagedWindowTitleButtonIsDisabled (TitleButton button, InternalWindowManager wm)
		{
			return (button.State & ButtonState.Inactive) == ButtonState.Inactive;
		}
		static bool ManagedWindowTitleButtonIsPressed (TitleButton button)
		{
			return (button.State & ButtonState.Pushed) == ButtonState.Pushed;
		}
		static VisualStyleElement ManagedWindowGetTitleButtonVisualStyleElement (TitleButton button, Form form)
		{
			if (form.WindowManager.IsToolWindow) {
				if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
					return VisualStyleElement.Window.SmallCloseButton.Disabled;
				if (ManagedWindowTitleButtonIsPressed (button))
					return VisualStyleElement.Window.SmallCloseButton.Pressed;
				if (button.Entered)
					return VisualStyleElement.Window.SmallCloseButton.Hot;
				return VisualStyleElement.Window.SmallCloseButton.Normal;
			}
			switch (button.Caption) {
			case CaptionButton.Close:
				if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
					return VisualStyleElement.Window.CloseButton.Disabled;
				if (ManagedWindowTitleButtonIsPressed (button))
					return VisualStyleElement.Window.CloseButton.Pressed;
				if (button.Entered)
					return VisualStyleElement.Window.CloseButton.Hot;
				return VisualStyleElement.Window.CloseButton.Normal;
			case CaptionButton.Help:
				if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
					return VisualStyleElement.Window.HelpButton.Disabled;
				if (ManagedWindowTitleButtonIsPressed (button))
					return VisualStyleElement.Window.HelpButton.Pressed;
				if (button.Entered)
					return VisualStyleElement.Window.HelpButton.Hot;
				return VisualStyleElement.Window.HelpButton.Normal;
			case CaptionButton.Maximize:
				if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
					return VisualStyleElement.Window.MaxButton.Disabled;
				if (ManagedWindowTitleButtonIsPressed (button))
					return VisualStyleElement.Window.MaxButton.Pressed;
				if (button.Entered)
					return VisualStyleElement.Window.MaxButton.Hot;
				return VisualStyleElement.Window.MaxButton.Normal;
			case CaptionButton.Minimize:
				if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
					return VisualStyleElement.Window.MinButton.Disabled;
				if (ManagedWindowTitleButtonIsPressed (button))
					return VisualStyleElement.Window.MinButton.Pressed;
				if (button.Entered)
					return VisualStyleElement.Window.MinButton.Hot;
				return VisualStyleElement.Window.MinButton.Normal;
			default:
				if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
					return VisualStyleElement.Window.RestoreButton.Disabled;
				if (ManagedWindowTitleButtonIsPressed (button))
					return VisualStyleElement.Window.RestoreButton.Pressed;
				if (button.Entered)
					return VisualStyleElement.Window.RestoreButton.Hot;
				return VisualStyleElement.Window.RestoreButton.Normal;
			}
		}
		protected override void ManagedWindowDrawTitleButton (Graphics dc, TitleButton button, Rectangle clip, Form form)
		{
			if (!render_non_client_areas) {
				base.ManagedWindowDrawTitleButton (dc, button, clip, form);
				return;
			}
			VisualStyleElement element = ManagedWindowGetTitleButtonVisualStyleElement (button, form);
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.ManagedWindowDrawTitleButton (dc, button, clip, form);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (dc, button.Rectangle, clip);
		}
		public override Size ManagedWindowButtonSize (InternalWindowManager wm)
		{
			if (!render_non_client_areas)
				return base.ManagedWindowButtonSize (wm);
			VisualStyleElement element = wm.IsToolWindow && !wm.IsMinimized ?
				VisualStyleElement.Window.SmallCloseButton.Normal :
				VisualStyleElement.Window.CloseButton.Normal;
			if (!VisualStyleRenderer.IsElementDefined (element))
				return base.ManagedWindowButtonSize (wm);
			IDeviceContext dc = GetMeasurementDeviceContext ();
			Size result = new VisualStyleRenderer (element).GetPartSize (dc, ThemeSizeType.True);
			ReleaseMeasurementDeviceContext (dc);
			return result;
		}
		public override void ManagedWindowDrawMenuButton (Graphics dc, TitleButton button, Rectangle clip, InternalWindowManager wm)
		{
			if (!render_non_client_areas) {
				base.ManagedWindowDrawMenuButton (dc, button, clip, wm);
				return;
			}
			VisualStyleElement element = ManagedWindowGetMenuButtonVisualStyleElement (button, wm);
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.ManagedWindowDrawMenuButton (dc, button, clip, wm);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (dc, button.Rectangle, clip);
		}
		static VisualStyleElement ManagedWindowGetMenuButtonVisualStyleElement (TitleButton button, InternalWindowManager wm)
		{
			switch (button.Caption) {
			case CaptionButton.Close:
				if (ManagedWindowTitleButtonIsDisabled (button, wm))
					return VisualStyleElement.Window.MdiCloseButton.Disabled;
				if (ManagedWindowTitleButtonIsPressed (button))
					return VisualStyleElement.Window.MdiCloseButton.Pressed;
				if (button.Entered)
					return VisualStyleElement.Window.MdiCloseButton.Hot;
				return VisualStyleElement.Window.MdiCloseButton.Normal;
			case CaptionButton.Help:
				if (ManagedWindowTitleButtonIsDisabled (button, wm))
					return VisualStyleElement.Window.MdiHelpButton.Disabled;
				if (ManagedWindowTitleButtonIsPressed (button))
					return VisualStyleElement.Window.MdiHelpButton.Pressed;
				if (button.Entered)
					return VisualStyleElement.Window.MdiHelpButton.Hot;
				return VisualStyleElement.Window.MdiHelpButton.Normal;
			case CaptionButton.Minimize:
				if (ManagedWindowTitleButtonIsDisabled (button, wm))
					return VisualStyleElement.Window.MdiMinButton.Disabled;
				if (ManagedWindowTitleButtonIsPressed (button))
					return VisualStyleElement.Window.MdiMinButton.Pressed;
				if (button.Entered)
					return VisualStyleElement.Window.MdiMinButton.Hot;
				return VisualStyleElement.Window.MdiMinButton.Normal;
			default:
				if (ManagedWindowTitleButtonIsDisabled (button, wm))
					return VisualStyleElement.Window.MdiRestoreButton.Disabled;
				if (ManagedWindowTitleButtonIsPressed (button))
					return VisualStyleElement.Window.MdiRestoreButton.Pressed;
				if (button.Entered)
					return VisualStyleElement.Window.MdiRestoreButton.Hot;
				return VisualStyleElement.Window.MdiRestoreButton.Normal;
			}
		}
		#endregion
		#region ProgressBar
		public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
		{
			if (!RenderClientAreas ||
				!VisualStyleRenderer.IsElementDefined (VisualStyleElement.ProgressBar.Bar.Normal) ||
				!VisualStyleRenderer.IsElementDefined (VisualStyleElement.ProgressBar.Chunk.Normal)) {
				base.DrawProgressBar (dc, clip_rect, ctrl);
				return;
			}
			VisualStyleRenderer renderer = new VisualStyleRenderer (VisualStyleElement.ProgressBar.Bar.Normal);
			renderer.DrawBackground (dc, ctrl.ClientRectangle, clip_rect);
			Rectangle client_area = renderer.GetBackgroundContentRectangle (dc, new Rectangle (Point.Empty, ctrl.Size));
			renderer = new VisualStyleRenderer (VisualStyleElement.ProgressBar.Chunk.Normal);
			/* Draw Blocks */
			int draw_mode = 0;
			int max_blocks = int.MaxValue;
			int start_pixel = client_area.X;
			draw_mode = (int)ctrl.Style;
			switch (draw_mode) {
			case 1: // Continuous
				client_area.Width = (int)(client_area.Width * ((double)(ctrl.Value - ctrl.Minimum) / (double)(Math.Max (ctrl.Maximum - ctrl.Minimum, 1))));
				renderer.DrawBackground (dc, client_area, clip_rect);
				break;
			case 2: // Marquee
				int ms_diff = (int)(DateTime.Now - ctrl.start).TotalMilliseconds;
				double percent_done = (double) ms_diff / ProgressBarMarqueeSpeedScaling 
					% (double)ctrl.MarqueeAnimationSpeed / (double)ctrl.MarqueeAnimationSpeed;
				max_blocks = 5;
				start_pixel = client_area.X + (int)(client_area.Width * percent_done);
				goto default;
			default: // Blocks
				int block_width = renderer.GetInteger (IntegerProperty.ProgressChunkSize);
				block_width = Math.Max (block_width, 0); // block_width is used to break out the loop below, it must be >= 0!
				int first_pixel_outside_filled_area = (int)(((double)(ctrl.Value - ctrl.Minimum) * client_area.Width) / (Math.Max (ctrl.Maximum - ctrl.Minimum, 1))) + client_area.X;
				int block_count = 0;
				int increment = block_width + renderer.GetInteger (IntegerProperty.ProgressSpaceSize);
				Rectangle block_rect = new Rectangle (start_pixel, client_area.Y, block_width, client_area.Height);
				while (true) {
					if (max_blocks != int.MaxValue) {
						if (block_count == max_blocks)
							break;
						if (block_rect.Right >= client_area.Width)
							block_rect.X -= client_area.Width;
					} else {
						if (block_rect.X >= first_pixel_outside_filled_area)
							break;
						if (block_rect.Right >= first_pixel_outside_filled_area)
							if (first_pixel_outside_filled_area == client_area.Right)
								block_rect.Width = first_pixel_outside_filled_area - block_rect.X;
							else
								break;
					}
					if (clip_rect.IntersectsWith (block_rect))
						renderer.DrawBackground (dc, block_rect, clip_rect);
					block_rect.X += increment;
					block_count++;
				}
				break;
			}
		}
		#endregion
		#region RadioButton
		protected override void RadioButton_DrawButton (RadioButton radio_button, Graphics dc, ButtonState state, Rectangle radiobutton_rectangle) {
			if (radio_button.Appearance == Appearance.Normal && radio_button.FlatStyle == FlatStyle.System) {
				RadioButtonRenderer.DrawRadioButton (
					dc,
					new Point (radiobutton_rectangle.Left, radiobutton_rectangle.Top),
					GetRadioButtonState (radio_button)
				);
				return;
			}
			base.RadioButton_DrawButton(radio_button, dc, state, radiobutton_rectangle);
		}
		static RadioButtonState GetRadioButtonState (RadioButton checkBox)
		{
			if (checkBox.Checked) {
				if (!checkBox.Enabled)
					return RadioButtonState.CheckedDisabled;
				else if (checkBox.Pressed)
					return RadioButtonState.CheckedPressed;
				else if (checkBox.Entered)
					return RadioButtonState.CheckedHot;
				return RadioButtonState.CheckedNormal;
			} else {
				if (!checkBox.Enabled)
					return RadioButtonState.UncheckedDisabled;
				else if (checkBox.Pressed)
					return RadioButtonState.UncheckedPressed;
				else if (checkBox.Entered)
					return RadioButtonState.UncheckedHot;
				return RadioButtonState.UncheckedNormal;
			}
		}
		#endregion
		#region ScrollBar
		public override void DrawScrollBar (Graphics dc, Rectangle clip, ScrollBar bar)
		{
			if (!RenderClientAreas ||
				!ScrollBarAreElementsDefined) {
				base.DrawScrollBar (dc, clip, bar);
				return;
			}
			VisualStyleElement element;
			VisualStyleRenderer renderer;
			int scroll_button_width = bar.scrollbutton_width;
			int scroll_button_height = bar.scrollbutton_height;
			if (bar.vert) {
				bar.FirstArrowArea = new Rectangle (0, 0, bar.Width, scroll_button_height);
				bar.SecondArrowArea = new Rectangle (
					0,
					bar.ClientRectangle.Height - scroll_button_height,
					bar.Width,
					scroll_button_height);
				Rectangle thumb_pos = bar.ThumbPos;
				thumb_pos.Width = bar.Width;
				bar.ThumbPos = thumb_pos;
				#region Background, upper track
				if (bar.thumb_moving == ScrollBar.ThumbMoving.Backwards)
					element = VisualStyleElement.ScrollBar.LowerTrackVertical.Pressed;
				else
					element = bar.Enabled ?
						VisualStyleElement.ScrollBar.LowerTrackVertical.Normal :
						VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled;
				renderer = new VisualStyleRenderer (element);
				Rectangle upper_track_rect = new Rectangle (
					0,
					0,
					bar.ClientRectangle.Width,
					bar.ThumbPos.Top);
				if (clip.IntersectsWith (upper_track_rect))
					renderer.DrawBackground (dc, upper_track_rect, clip);
				#endregion
				#region Background, lower track
				if (bar.thumb_moving == ScrollBar.ThumbMoving.Forward)
					element = VisualStyles.VisualStyleElement.ScrollBar.LowerTrackVertical.Pressed;
				else
					element = bar.Enabled ?
						VisualStyleElement.ScrollBar.LowerTrackVertical.Normal :
						VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled;
				renderer = new VisualStyleRenderer (element);
				Rectangle lower_track_rect = new Rectangle (
					0,
					bar.ThumbPos.Bottom,
					bar.ClientRectangle.Width,
					bar.ClientRectangle.Height - bar.ThumbPos.Bottom);
				if (clip.IntersectsWith (lower_track_rect))
					renderer.DrawBackground (dc, lower_track_rect, clip);
				#endregion
				#region Buttons
				if (clip.IntersectsWith (bar.FirstArrowArea)) {
					if (!bar.Enabled)
						element = VisualStyleElement.ScrollBar.ArrowButton.UpDisabled;
					else if (bar.firstbutton_state == ButtonState.Pushed)
						element = VisualStyleElement.ScrollBar.ArrowButton.UpPressed;
					else if (bar.FirstButtonEntered)
						element = VisualStyleElement.ScrollBar.ArrowButton.UpHot;
					else if (ScrollBarHasHoverArrowButtonStyleVisualStyles && bar.Entered)
						element = VisualStyleElement.ScrollBar.ArrowButton.UpHover;
					else
						element = VisualStyleElement.ScrollBar.ArrowButton.UpNormal;
					renderer = new VisualStyleRenderer (element);
					renderer.DrawBackground (dc, bar.FirstArrowArea);
				}
				if (clip.IntersectsWith (bar.SecondArrowArea)) {
					if (!bar.Enabled)
						element = VisualStyleElement.ScrollBar.ArrowButton.DownDisabled;
					else if (bar.secondbutton_state == ButtonState.Pushed)
						element = VisualStyleElement.ScrollBar.ArrowButton.DownPressed;
					else if (bar.SecondButtonEntered)
						element = VisualStyleElement.ScrollBar.ArrowButton.DownHot;
					else if (ScrollBarHasHoverArrowButtonStyleVisualStyles && bar.Entered)
						element = VisualStyleElement.ScrollBar.ArrowButton.DownHover;
					else
						element = VisualStyleElement.ScrollBar.ArrowButton.DownNormal;
					renderer = new VisualStyleRenderer (element);
					renderer.DrawBackground (dc, bar.SecondArrowArea);
				}
				#endregion
				#region Thumb and grip
				if (!bar.Enabled)
					element = VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled;
				else if (bar.ThumbPressed)
					element = VisualStyleElement.ScrollBar.ThumbButtonVertical.Pressed;
				else if (bar.ThumbEntered)
					element = VisualStyleElement.ScrollBar.ThumbButtonVertical.Hot;
				else
					element = VisualStyleElement.ScrollBar.ThumbButtonVertical.Normal;
				renderer = new VisualStyleRenderer (element);
				renderer.DrawBackground (dc, bar.ThumbPos, clip);

				if (bar.Enabled && bar.ThumbPos.Height >= 20) {
					element = VisualStyleElement.ScrollBar.GripperVertical.Normal;
					if (VisualStyleRenderer.IsElementDefined (element)) {
						renderer = new VisualStyleRenderer (element);
						renderer.DrawBackground (dc, bar.ThumbPos, clip);
					}
				}
				#endregion
			} else {
				bar.FirstArrowArea = new Rectangle (0, 0, scroll_button_width, bar.Height);
				bar.SecondArrowArea = new Rectangle (
					bar.ClientRectangle.Width - scroll_button_width,
					0,
					scroll_button_width,
					bar.Height);
				Rectangle thumb_pos = bar.ThumbPos;
				thumb_pos.Height = bar.Height;
				bar.ThumbPos = thumb_pos;
				#region Background, left track
				if (bar.thumb_moving == ScrollBar.ThumbMoving.Backwards)
					element = VisualStyleElement.ScrollBar.LeftTrackHorizontal.Pressed;
				else
					element = bar.Enabled ?
						VisualStyleElement.ScrollBar.LeftTrackHorizontal.Normal :
						VisualStyleElement.ScrollBar.LeftTrackHorizontal.Disabled;
				renderer = new VisualStyleRenderer (element);
				Rectangle left_track_rect = new Rectangle (
					0,
					0,
					bar.ThumbPos.Left,
					bar.ClientRectangle.Height);
				if (clip.IntersectsWith (left_track_rect))
					renderer.DrawBackground (dc, left_track_rect, clip);
				#endregion
				#region Background, right track
				if (bar.thumb_moving == ScrollBar.ThumbMoving.Forward)
					element = VisualStyleElement.ScrollBar.RightTrackHorizontal.Pressed;
				else
					element = bar.Enabled ?
						VisualStyleElement.ScrollBar.RightTrackHorizontal.Normal :
						VisualStyleElement.ScrollBar.RightTrackHorizontal.Disabled;
				renderer = new VisualStyleRenderer (element);
				Rectangle right_track_rect = new Rectangle (
					bar.ThumbPos.Right,
					0,
					bar.ClientRectangle.Width - bar.ThumbPos.Right,
					bar.ClientRectangle.Height);
				if (clip.IntersectsWith (right_track_rect))
					renderer.DrawBackground (dc, right_track_rect, clip);
				#endregion
				#region Buttons
				if (clip.IntersectsWith (bar.FirstArrowArea)) {
					if (!bar.Enabled)
						element = VisualStyleElement.ScrollBar.ArrowButton.LeftDisabled;
					else if (bar.firstbutton_state == ButtonState.Pushed)
						element = VisualStyleElement.ScrollBar.ArrowButton.LeftPressed;
					else if (bar.FirstButtonEntered)
						element = VisualStyleElement.ScrollBar.ArrowButton.LeftHot;
					else if (ScrollBarHasHoverArrowButtonStyleVisualStyles && bar.Entered)
						element = VisualStyleElement.ScrollBar.ArrowButton.LeftHover;
					else
						element = VisualStyleElement.ScrollBar.ArrowButton.LeftNormal;
					renderer = new VisualStyleRenderer (element);
					renderer.DrawBackground (dc, bar.FirstArrowArea);
				}
				if (clip.IntersectsWith (bar.SecondArrowArea)) {
					if (!bar.Enabled)
						element = VisualStyleElement.ScrollBar.ArrowButton.RightDisabled;
					else if (bar.secondbutton_state == ButtonState.Pushed)
						element = VisualStyleElement.ScrollBar.ArrowButton.RightPressed;
					else if (bar.SecondButtonEntered)
						element = VisualStyleElement.ScrollBar.ArrowButton.RightHot;
					else if (ScrollBarHasHoverArrowButtonStyleVisualStyles && bar.Entered)
						element = VisualStyleElement.ScrollBar.ArrowButton.RightHover;
					else
						element = VisualStyleElement.ScrollBar.ArrowButton.RightNormal;
					renderer = new VisualStyleRenderer (element);
					renderer.DrawBackground (dc, bar.SecondArrowArea);
				}
				#endregion
				#region Thumb and grip
				if (!bar.Enabled)
					element = VisualStyleElement.ScrollBar.RightTrackHorizontal.Disabled;
				else if (bar.ThumbPressed)
					element = VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Pressed;
				else if (bar.ThumbEntered)
					element = VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Hot;
				else
					element = VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Normal;
				renderer = new VisualStyleRenderer (element);
				renderer.DrawBackground (dc, bar.ThumbPos, clip);

				if (bar.Enabled && bar.ThumbPos.Height >= 20) {
					element = VisualStyleElement.ScrollBar.GripperHorizontal.Normal;
					if (VisualStyleRenderer.IsElementDefined (element)) {
						renderer = new VisualStyleRenderer (element);
						renderer.DrawBackground (dc, bar.ThumbPos, clip);
					}
				}
				#endregion
			}
		}
		public override bool ScrollBarHasHotElementStyles {
			get {
				if (!RenderClientAreas)
					return base.ScrollBarHasHotElementStyles;
				return ScrollBarAreElementsDefined;
			}
		}
		public override bool ScrollBarHasPressedThumbStyle {
			get {
				if (!RenderClientAreas)
					return base.ScrollBarHasPressedThumbStyle;
				return ScrollBarAreElementsDefined;
			}
		}
		const int WindowsVistaMajorVersion = 6;
		static bool ScrollBarHasHoverArrowButtonStyleVisualStyles =
			Environment.OSVersion.Version.Major >= WindowsVistaMajorVersion;
		public override bool ScrollBarHasHoverArrowButtonStyle {
			get {
				if (RenderClientAreas &&
					ScrollBarHasHoverArrowButtonStyleVisualStyles)
					return ScrollBarAreElementsDefined;
				return base.ScrollBarHasHoverArrowButtonStyle;
			}
		}
		static bool ScrollBarAreElementsDefined {
			get {
				return
					VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.ArrowButton.DownDisabled) &&
					VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.LeftTrackHorizontal.Disabled) &&
					VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled) &&
					VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.RightTrackHorizontal.Disabled) &&
					VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Disabled) &&
					VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.ThumbButtonVertical.Disabled) &&
					VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.UpperTrackVertical.Disabled);
			}
		}
		#endregion
		#region StatusBar
		protected override void DrawStatusBarBackground(Graphics dc, Rectangle clip, StatusBar sb) {
			if (!RenderClientAreas) {
				base.DrawStatusBarBackground (dc, clip, sb);
				return;
			}
			VisualStyleElement element = VisualStyleElement.Status.Bar.Normal;
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.DrawStatusBarBackground (dc, clip, sb);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (dc, sb.ClientRectangle, clip);
		}
		protected override void DrawStatusBarSizingGrip (Graphics dc, Rectangle clip, StatusBar sb, Rectangle area)
		{
			if (!RenderClientAreas) {
				base.DrawStatusBarSizingGrip (dc, clip, sb, area);
				return;
			}
			VisualStyleElement element = VisualStyleElement.Status.Gripper.Normal;
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.DrawStatusBarSizingGrip (dc, clip, sb, area);
				return;
			}
			VisualStyleRenderer renderer = new VisualStyleRenderer (element);
			Rectangle sizing_grip_rectangle = new Rectangle (Point.Empty, renderer.GetPartSize (dc, ThemeSizeType.True));
			sizing_grip_rectangle.X = sb.Width - sizing_grip_rectangle.Width;
			sizing_grip_rectangle.Y = sb.Height - sizing_grip_rectangle.Height;
			renderer.DrawBackground (dc, sizing_grip_rectangle, clip);
		}
		protected override void DrawStatusBarPanelBackground (Graphics dc, Rectangle area, StatusBarPanel panel)
		{
			if (!RenderClientAreas) {
				base.DrawStatusBarPanelBackground (dc, area, panel);
				return;
			}
			VisualStyleElement element = VisualStyleElement.Status.Pane.Normal;
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.DrawStatusBarPanelBackground (dc, area, panel);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (dc, area);
		}
		#endregion
		#region TextBoxBase
		static bool TextBoxBaseShouldPaint (TextBoxBase textBoxBase)
		{
			return textBoxBase.BorderStyle == BorderStyle.Fixed3D;
		}
		static VisualStyleElement TextBoxBaseGetVisualStyleElement (TextBoxBase textBoxBase)
		{
			if (!textBoxBase.Enabled)
				return VisualStyleElement.TextBox.TextEdit.Disabled;
			if (textBoxBase.ReadOnly)
				return VisualStyleElement.TextBox.TextEdit.ReadOnly;
			if (textBoxBase.Entered)
				return VisualStyleElement.TextBox.TextEdit.Hot;
			if (textBoxBase.Focused)
				return VisualStyleElement.TextBox.TextEdit.Focused;
			return VisualStyleElement.TextBox.TextEdit.Normal;
		}
		public override void TextBoxBaseFillBackground (TextBoxBase textBoxBase, Graphics g, Rectangle clippingArea)
		{
			if (!RenderClientAreas ||
				!TextBoxBaseShouldPaint (textBoxBase)) {
				base.TextBoxBaseFillBackground (textBoxBase, g, clippingArea);
				return;
			}
			VisualStyleElement element = TextBoxBaseGetVisualStyleElement (textBoxBase);
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.TextBoxBaseFillBackground (textBoxBase, g, clippingArea);
				return;
			}
			Rectangle bounds = new Rectangle(Point.Empty, textBoxBase.Size);
			bounds.X -= (bounds.Width - textBoxBase.ClientSize.Width) / 2;
			bounds.Y -= (bounds.Height - textBoxBase.ClientSize.Height) / 2;
			new VisualStyleRenderer (element).DrawBackground (g, bounds, clippingArea);
		}
		public override bool TextBoxBaseHandleWmNcPaint (TextBoxBase textBoxBase, ref Message m)
		{
			if (!RenderClientAreas ||
				!TextBoxBaseShouldPaint (textBoxBase))
				return base.TextBoxBaseHandleWmNcPaint (textBoxBase, ref m);
			VisualStyleElement element = TextBoxBaseGetVisualStyleElement (textBoxBase);
			if (!VisualStyleRenderer.IsElementDefined (element))
				return base.TextBoxBaseHandleWmNcPaint (textBoxBase, ref m);
			PaintEventArgs e = XplatUI.PaintEventStart (ref m, textBoxBase.Handle, false);
			new VisualStyleRenderer (element).DrawBackgroundExcludingArea (
				e.Graphics,
				new Rectangle (Point.Empty, textBoxBase.Size),
				new Rectangle (new Point ((textBoxBase.Width - textBoxBase.ClientSize.Width) / 2,
					(textBoxBase.Height - textBoxBase.ClientSize.Height) / 2),
					textBoxBase.ClientSize));
			XplatUI.PaintEventEnd (ref m, textBoxBase.Handle, false);
			return true;
		}
		public override bool TextBoxBaseShouldPaintBackground (TextBoxBase textBoxBase)
		{
			if (!RenderClientAreas ||
				!TextBoxBaseShouldPaint (textBoxBase))
				return base.TextBoxBaseShouldPaintBackground (textBoxBase);
			VisualStyleElement element = TextBoxBaseGetVisualStyleElement (textBoxBase);
			if (!VisualStyleRenderer.IsElementDefined (element))
				return base.TextBoxBaseShouldPaintBackground (textBoxBase);
			return new VisualStyleRenderer (element).IsBackgroundPartiallyTransparent ();
		}
		#endregion
		#region ToolBar
		static bool ToolBarIsDisabled (ToolBarItem item)
		{
			return !item.Button.Enabled;
		}
		static bool ToolBarIsPressed (ToolBarItem item)
		{
			return item.Pressed;
		}
		static bool ToolBarIsChecked (ToolBarItem item)
		{
			return item.Button.Pushed;
		}
		static bool ToolBarIsHot (ToolBarItem item)
		{
			return item.Hilight;
		}
		#region Border
		protected override void DrawToolBarButtonBorder (Graphics dc, ToolBarItem item, bool is_flat)
		{
			if (!RenderClientAreas) {
				base.DrawToolBarButtonBorder (dc, item, is_flat);
				return;
			}
			if (item.Button.Style == ToolBarButtonStyle.Separator)
				return;
			VisualStyleElement element;
			if (item.Button.Style == ToolBarButtonStyle.DropDownButton)
				element = ToolBarGetDropDownButtonVisualStyleElement (item);
			else
				element = ToolBarGetButtonVisualStyleElement (item);
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.DrawToolBarButtonBorder (dc, item, is_flat);
				return;
			}
			Rectangle rectangle = item.Rectangle;
			if (item.Button.Style == ToolBarButtonStyle.DropDownButton && item.Button.Parent.DropDownArrows)
				rectangle.Width -= ToolBarDropDownWidth;
			new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
		}
		private static VisualStyleElement ToolBarGetDropDownButtonVisualStyleElement (ToolBarItem item)
		{
			if (item.Button.Parent.DropDownArrows) {
				if (ToolBarIsDisabled (item))
					return VisualStyleElement.ToolBar.SplitButton.Disabled;
				if (ToolBarIsPressed (item))
					return VisualStyleElement.ToolBar.SplitButton.Pressed;
				if (ToolBarIsChecked (item))
					if (ToolBarIsHot (item))
						return VisualStyleElement.ToolBar.SplitButton.HotChecked;
					else
						return VisualStyleElement.ToolBar.SplitButton.Checked;
				if (ToolBarIsHot (item))
					return VisualStyleElement.ToolBar.SplitButton.Hot;
				return VisualStyleElement.ToolBar.SplitButton.Normal;
			} else {
				if (ToolBarIsDisabled (item))
					return VisualStyleElement.ToolBar.DropDownButton.Disabled;
				if (ToolBarIsPressed (item))
					return VisualStyleElement.ToolBar.DropDownButton.Pressed;
				if (ToolBarIsChecked (item))
					if (ToolBarIsHot (item))
						return VisualStyleElement.ToolBar.DropDownButton.HotChecked;
					else
						return VisualStyleElement.ToolBar.DropDownButton.Checked;
				if (ToolBarIsHot (item))
					return VisualStyleElement.ToolBar.DropDownButton.Hot;
				return VisualStyleElement.ToolBar.DropDownButton.Normal;
			}
		}
		private static VisualStyleElement ToolBarGetButtonVisualStyleElement (ToolBarItem item)
		{
			if (ToolBarIsDisabled (item))
				return VisualStyleElement.ToolBar.Button.Disabled;
			if (ToolBarIsPressed (item))
				return VisualStyleElement.ToolBar.Button.Pressed;
			if (ToolBarIsChecked (item))
				if (ToolBarIsHot (item))
					return VisualStyleElement.ToolBar.Button.HotChecked;
				else
					return VisualStyleElement.ToolBar.Button.Checked;
			if (ToolBarIsHot (item))
				return VisualStyleElement.ToolBar.Button.Hot;
			return VisualStyleElement.ToolBar.Button.Normal;
		}
		#endregion
		#region Separator
		protected override void DrawToolBarSeparator (Graphics dc, ToolBarItem item)
		{
			if (!RenderClientAreas) {
				base.DrawToolBarSeparator (dc, item);
				return;
			}
			VisualStyleElement element = ToolBarGetSeparatorVisualStyleElement (item);
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.DrawToolBarSeparator (dc, item);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (dc, item.Rectangle);
		}
		static VisualStyleElement ToolBarGetSeparatorVisualStyleElement (ToolBarItem toolBarItem)
		{
			return toolBarItem.Button.Parent.Vertical ?
				VisualStyleElement.ToolBar.SeparatorVertical.Normal :
				VisualStyleElement.ToolBar.SeparatorHorizontal.Normal;
		}
		#endregion
		#region Toggle button background
		protected override void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarItem item)
		{
			if (!RenderClientAreas ||
				!VisualStyleRenderer.IsElementDefined (ToolBarGetButtonVisualStyleElement (item)))
				base.DrawToolBarToggleButtonBackground (dc, item);
		}
		#endregion
		#region Drop down arrow
		protected override void DrawToolBarDropDownArrow (Graphics dc, ToolBarItem item, bool is_flat)
		{
			if (!RenderClientAreas) {
				base.DrawToolBarDropDownArrow (dc, item, is_flat);
				return;
			}
			VisualStyleElement element = ToolBarGetDropDownArrowVisualStyleElement (item);
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.DrawToolBarDropDownArrow (dc, item, is_flat);
				return;
			}
			Rectangle rect = item.Rectangle;
			rect.X = item.Rectangle.Right - ToolBarDropDownWidth;
			rect.Width = ToolBarDropDownWidth;
			new VisualStyleRenderer (element).DrawBackground (dc, rect);
		}
		private static VisualStyleElement ToolBarGetDropDownArrowVisualStyleElement (ToolBarItem item)
		{
			if (ToolBarIsDisabled (item))
				return VisualStyleElement.ToolBar.SplitButtonDropDown.Disabled;
			if (ToolBarIsPressed (item))
				return VisualStyleElement.ToolBar.SplitButtonDropDown.Pressed;
			if (ToolBarIsChecked (item))
				if (ToolBarIsHot (item))
					return VisualStyleElement.ToolBar.SplitButtonDropDown.HotChecked;
				else
					return VisualStyleElement.ToolBar.SplitButtonDropDown.Checked;
			if (ToolBarIsHot (item))
				return VisualStyleElement.ToolBar.SplitButtonDropDown.Hot;
			return VisualStyleElement.ToolBar.SplitButtonDropDown.Normal;
		}
		#endregion
		public override bool ToolBarHasHotElementStyles (ToolBar toolBar)
		{
			if (!RenderClientAreas)
				return base.ToolBarHasHotElementStyles (toolBar);
			return true;
		}
		public override bool ToolBarHasHotCheckedElementStyles {
			get {
				if (!RenderClientAreas)
					return base.ToolBarHasHotCheckedElementStyles;
				return true;
			}
		}
		#endregion
		#region ToolTip
		protected override void ToolTipDrawBackground (Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control)
		{
			if (!RenderClientAreas) {
				base.ToolTipDrawBackground (dc, clip_rectangle, control);
				return;
			}
			VisualStyleElement element = VisualStyleElement.ToolTip.Standard.Normal;
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.ToolTipDrawBackground (dc, clip_rectangle, control);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (dc, control.ClientRectangle);
		}
		public override bool ToolTipTransparentBackground {
			get {
				if (!RenderClientAreas)
					return base.ToolTipTransparentBackground;
				VisualStyleElement element = VisualStyleElement.ToolTip.Standard.Normal;
				if (!VisualStyleRenderer.IsElementDefined (element))
					return base.ToolTipTransparentBackground;
				return new VisualStyleRenderer (element).IsBackgroundPartiallyTransparent ();
			}
		}
		#endregion
		#region TrackBar
		protected override Size TrackBarGetThumbSize (TrackBar trackBar)
		{
			if (!RenderClientAreas)
				return base.TrackBarGetThumbSize (trackBar);
			VisualStyleElement element = TrackBarGetThumbVisualStyleElement (trackBar);
			if (!VisualStyleRenderer.IsElementDefined (element))
				return base.TrackBarGetThumbSize (trackBar);
			Graphics g = trackBar.CreateGraphics ();
			Size result = new VisualStyleRenderer (element).GetPartSize (g, ThemeSizeType.True);
			g.Dispose ();
			return trackBar.Orientation == Orientation.Horizontal ? result : TrackBarRotateVerticalThumbSize (result);
		}
		static VisualStyleElement TrackBarGetThumbVisualStyleElement (TrackBar trackBar)
		{
			if (trackBar.Orientation == Orientation.Horizontal)
				switch (trackBar.TickStyle) {
				case TickStyle.BottomRight:
				case TickStyle.None:
					return TrackBarGetHorizontalThumbBottomVisualStyleElement (trackBar);
				case TickStyle.TopLeft:
					return TrackBarGetHorizontalThumbTopVisualStyleElement (trackBar);
				default:
					return TrackBarGetHorizontalThumbVisualStyleElement (trackBar);
				}
			else
				switch (trackBar.TickStyle) {
				case TickStyle.BottomRight:
				case TickStyle.None:
					return TrackBarGetVerticalThumbRightVisualStyleElement (trackBar);
				case TickStyle.TopLeft:
					return TrackBarGetVerticalThumbLeftVisualStyleElement (trackBar);
				default:
					return TrackBarGetVerticalThumbVisualStyleElement (trackBar);
				}
		}
		static Size TrackBarRotateVerticalThumbSize (Size value)
		{
			int temporary = value.Width;
			value.Width = value.Height;
			value.Height = temporary;
			return value;
		}
		#region Track
		protected override void TrackBarDrawHorizontalTrack (Graphics dc, Rectangle thumb_area, Point channel_startpoint, Rectangle clippingArea)
		{
			if (!RenderClientAreas) {
				base.TrackBarDrawHorizontalTrack (dc, thumb_area, channel_startpoint, clippingArea);
				return;
			}
			VisualStyleElement element = VisualStyleElement.TrackBar.Track.Normal;
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.TrackBarDrawHorizontalTrack (dc, thumb_area, channel_startpoint, clippingArea);
				return;
			}
			VisualStyleRenderer renderer = new VisualStyleRenderer (element);
			renderer.DrawBackground (dc, new Rectangle (channel_startpoint, new Size (thumb_area.Width, renderer.GetPartSize (dc, ThemeSizeType.True).Height)), clippingArea);
		}
		protected override void TrackBarDrawVerticalTrack (Graphics dc, Rectangle thumb_area, Point channel_startpoint, Rectangle clippingArea)
		{
			if (!RenderClientAreas) {
				base.TrackBarDrawVerticalTrack (dc, thumb_area, channel_startpoint, clippingArea);
				return;
			}
			VisualStyleElement element = VisualStyleElement.TrackBar.TrackVertical.Normal;
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.TrackBarDrawVerticalTrack (dc, thumb_area, channel_startpoint, clippingArea);
				return;
			}
			VisualStyleRenderer renderer = new VisualStyleRenderer (element);
			renderer.DrawBackground (dc, new Rectangle (channel_startpoint, new Size (renderer.GetPartSize (dc, ThemeSizeType.True).Width, thumb_area.Height)), clippingArea);
		}
		#endregion
		#region Thumb
		static bool TrackBarIsDisabled (TrackBar trackBar)
		{
			return !trackBar.Enabled;
		}
		static bool TrackBarIsHot (TrackBar trackBar)
		{
			return trackBar.ThumbEntered;
		}
		static bool TrackBarIsPressed (TrackBar trackBar)
		{
			return trackBar.thumb_pressed;
		}
		static bool TrackBarIsFocused (TrackBar trackBar)
		{
			return trackBar.Focused;
		}
		#region Horizontal
		protected override void TrackBarDrawHorizontalThumbBottom (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
		{
			if (!RenderClientAreas) {
				base.TrackBarDrawHorizontalThumbBottom (dc, thumb_pos, br_thumb, clippingArea, trackBar);
				return;
			}
			VisualStyleElement element = TrackBarGetHorizontalThumbBottomVisualStyleElement (trackBar);
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.TrackBarDrawHorizontalThumbBottom (dc, thumb_pos, br_thumb, clippingArea, trackBar);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (dc, thumb_pos, clippingArea);
		}
		static VisualStyleElement TrackBarGetHorizontalThumbBottomVisualStyleElement (TrackBar trackBar)
		{
			if (TrackBarIsDisabled (trackBar))
				return VisualStyleElement.TrackBar.ThumbBottom.Disabled;
			else if (TrackBarIsPressed (trackBar))
				return VisualStyleElement.TrackBar.ThumbBottom.Pressed;
			else if (TrackBarIsHot (trackBar))
				return VisualStyleElement.TrackBar.ThumbBottom.Hot;
			else if (TrackBarIsFocused (trackBar))
				return VisualStyleElement.TrackBar.ThumbBottom.Focused;
			return VisualStyleElement.TrackBar.ThumbBottom.Normal;
		}
		protected override void TrackBarDrawHorizontalThumbTop (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
		{
			if (!RenderClientAreas) {
				base.TrackBarDrawHorizontalThumbTop (dc, thumb_pos, br_thumb, clippingArea, trackBar);
				return;
			}
			VisualStyleElement element = TrackBarGetHorizontalThumbTopVisualStyleElement (trackBar);
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.TrackBarDrawHorizontalThumbTop (dc, thumb_pos, br_thumb, clippingArea, trackBar);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (dc, thumb_pos, clippingArea);
		}
		static VisualStyleElement TrackBarGetHorizontalThumbTopVisualStyleElement (TrackBar trackBar)
		{
			if (TrackBarIsDisabled (trackBar))
				return VisualStyleElement.TrackBar.ThumbTop.Disabled;
			else if (TrackBarIsPressed (trackBar))
				return VisualStyleElement.TrackBar.ThumbTop.Pressed;
			else if (TrackBarIsHot (trackBar))
				return VisualStyleElement.TrackBar.ThumbTop.Hot;
			else if (TrackBarIsFocused (trackBar))
				return VisualStyleElement.TrackBar.ThumbTop.Focused;
			return VisualStyleElement.TrackBar.ThumbTop.Normal;
		}
		protected override void TrackBarDrawHorizontalThumb (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
		{
			if (!RenderClientAreas) {
				base.TrackBarDrawHorizontalThumb (dc, thumb_pos, br_thumb, clippingArea, trackBar);
				return;
			}
			VisualStyleElement element = TrackBarGetHorizontalThumbVisualStyleElement (trackBar);
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.TrackBarDrawHorizontalThumb (dc, thumb_pos, br_thumb, clippingArea, trackBar);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (dc, thumb_pos, clippingArea);
		}
		static VisualStyleElement TrackBarGetHorizontalThumbVisualStyleElement (TrackBar trackBar)
		{
			if (TrackBarIsDisabled (trackBar))
				return VisualStyleElement.TrackBar.Thumb.Disabled;
			else if (TrackBarIsPressed (trackBar))
				return VisualStyleElement.TrackBar.Thumb.Pressed;
			else if (TrackBarIsHot (trackBar))
				return VisualStyleElement.TrackBar.Thumb.Hot;
			else if (TrackBarIsFocused (trackBar))
				return VisualStyleElement.TrackBar.Thumb.Focused;
			return VisualStyleElement.TrackBar.Thumb.Normal;
		}
		#endregion
		#region Vertical
		static Rectangle TrackBarRotateVerticalThumbSize (Rectangle value)
		{
			int temporary = value.Width;
			value.Width = value.Height;
			value.Height = temporary;
			return value;
		}
		protected override void TrackBarDrawVerticalThumbRight (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
		{
			if (!RenderClientAreas) {
				base.TrackBarDrawVerticalThumbRight (dc, thumb_pos, br_thumb, clippingArea, trackBar);
				return;
			}
			VisualStyleElement element = TrackBarGetVerticalThumbRightVisualStyleElement (trackBar);
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.TrackBarDrawVerticalThumbRight (dc, thumb_pos, br_thumb, clippingArea, trackBar);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (dc, TrackBarRotateVerticalThumbSize (thumb_pos), clippingArea);
		}
		static VisualStyleElement TrackBarGetVerticalThumbRightVisualStyleElement (TrackBar trackBar)
		{
			if (TrackBarIsDisabled (trackBar))
				return VisualStyleElement.TrackBar.ThumbRight.Disabled;
			else if (TrackBarIsPressed (trackBar))
				return VisualStyleElement.TrackBar.ThumbRight.Pressed;
			else if (TrackBarIsHot (trackBar))
				return VisualStyleElement.TrackBar.ThumbRight.Hot;
			else if (TrackBarIsFocused (trackBar))
				return VisualStyleElement.TrackBar.ThumbRight.Focused;
			return VisualStyleElement.TrackBar.ThumbRight.Normal;
		}
		protected override void TrackBarDrawVerticalThumbLeft (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
		{
			if (!RenderClientAreas) {
				base.TrackBarDrawVerticalThumbLeft (dc, thumb_pos, br_thumb, clippingArea, trackBar);
				return;
			}
			VisualStyleElement element = TrackBarGetVerticalThumbLeftVisualStyleElement (trackBar);
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.TrackBarDrawVerticalThumbLeft (dc, thumb_pos, br_thumb, clippingArea, trackBar);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (dc, TrackBarRotateVerticalThumbSize (thumb_pos), clippingArea);
		}
		static VisualStyleElement TrackBarGetVerticalThumbLeftVisualStyleElement (TrackBar trackBar)
		{
			if (TrackBarIsDisabled (trackBar))
				return VisualStyleElement.TrackBar.ThumbLeft.Disabled;
			else if (TrackBarIsPressed (trackBar))
				return VisualStyleElement.TrackBar.ThumbLeft.Pressed;
			else if (TrackBarIsHot (trackBar))
				return VisualStyleElement.TrackBar.ThumbLeft.Hot;
			else if (TrackBarIsFocused (trackBar))
				return VisualStyleElement.TrackBar.ThumbLeft.Focused;
			return VisualStyleElement.TrackBar.ThumbLeft.Normal;
		}
		protected override void TrackBarDrawVerticalThumb (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
		{
			if (!RenderClientAreas) {
				base.TrackBarDrawVerticalThumb (dc, thumb_pos, br_thumb, clippingArea, trackBar);
				return;
			}
			VisualStyleElement element = TrackBarGetVerticalThumbVisualStyleElement (trackBar);
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.TrackBarDrawVerticalThumb (dc, thumb_pos, br_thumb, clippingArea, trackBar);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (dc, TrackBarRotateVerticalThumbSize (thumb_pos), clippingArea);
		}
		static VisualStyleElement TrackBarGetVerticalThumbVisualStyleElement (TrackBar trackBar)
		{
			if (TrackBarIsDisabled (trackBar))
				return VisualStyleElement.TrackBar.ThumbVertical.Disabled;
			else if (TrackBarIsPressed (trackBar))
				return VisualStyleElement.TrackBar.ThumbVertical.Pressed;
			else if (TrackBarIsHot (trackBar))
				return VisualStyleElement.TrackBar.ThumbVertical.Hot;
			else if (TrackBarIsFocused (trackBar))
				return VisualStyleElement.TrackBar.ThumbVertical.Focused;
			return VisualStyleElement.TrackBar.ThumbVertical.Normal;
		}
		#endregion
		#endregion
		#region Ticks
		const EdgeStyle TrackBarTickEdgeStyle = EdgeStyle.Bump;
		const EdgeEffects TrackBarTickEdgeEffects = EdgeEffects.None;
		#region Horizontal
		protected override ITrackBarTickPainter TrackBarGetHorizontalTickPainter (Graphics g)
		{
			if (!RenderClientAreas ||
				!VisualStyleRenderer.IsElementDefined (VisualStyleElement.TrackBar.Ticks.Normal))
				return base.TrackBarGetHorizontalTickPainter (g);
			return new TrackBarHorizontalTickPainter (g);
		}
		class TrackBarHorizontalTickPainter : ITrackBarTickPainter
		{
			readonly Graphics g;
			readonly VisualStyleRenderer renderer;
			public TrackBarHorizontalTickPainter (Graphics g)
			{
				this.g = g;
				renderer = new VisualStyleRenderer (VisualStyleElement.TrackBar.Ticks.Normal);
			}
			public void Paint (float x1, float y1, float x2, float y2)
			{
				renderer.DrawEdge (g, new Rectangle (
					(int)Math.Round (x1),
					(int)Math.Round (y1),
					1,
					(int)Math.Round (y2 - y1) + 1), Edges.Left, TrackBarTickEdgeStyle, TrackBarTickEdgeEffects);
			}
		}
		#endregion
		#region Vertical
		protected override ITrackBarTickPainter TrackBarGetVerticalTickPainter (Graphics g)
		{
			if (!RenderClientAreas ||
				!VisualStyleRenderer.IsElementDefined (VisualStyleElement.TrackBar.TicksVertical.Normal))
				return base.TrackBarGetVerticalTickPainter (g);
			return new TrackBarVerticalTickPainter (g);
		}
		class TrackBarVerticalTickPainter : ITrackBarTickPainter
		{
			readonly Graphics g;
			readonly VisualStyleRenderer renderer;
			public TrackBarVerticalTickPainter (Graphics g)
			{
				this.g = g;
				renderer = new VisualStyleRenderer (VisualStyleElement.TrackBar.TicksVertical.Normal);
			}
			public void Paint (float x1, float y1, float x2, float y2)
			{
				renderer.DrawEdge (g, new Rectangle (
					(int)Math.Round (x1),
					(int)Math.Round (y1),
					(int)Math.Round (x2 - x1) + 1,
					1), Edges.Top, TrackBarTickEdgeStyle, TrackBarTickEdgeEffects);
			}
		}
		#endregion
		#endregion
		public override bool TrackBarHasHotThumbStyle {
			get {
				if (!RenderClientAreas)
					return base.TrackBarHasHotThumbStyle;
				return true;
			}
		}
		#endregion
		#region TreeView
		[MonoInternalNote ("Use the sizing information provided by the VisualStyles API.")]
		public override void TreeViewDrawNodePlusMinus (TreeView treeView, TreeNode node, Graphics dc, int x, int middle)
		{
			if (!RenderClientAreas) {
				base.TreeViewDrawNodePlusMinus (treeView, node, dc, x, middle);
				return;
			}
			VisualStyleElement element = node.IsExpanded ?
				VisualStyleElement.TreeView.Glyph.Opened : 
				VisualStyleElement.TreeView.Glyph.Closed;
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.TreeViewDrawNodePlusMinus (treeView, node, dc, x, middle);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (dc, new Rectangle (x, middle - 4, 9, 9));
		}
		#endregion
		#region UpDownBase
		public override void UpDownBaseDrawButton (Graphics g, Rectangle bounds, bool top, PushButtonState state)
		{
			if (!RenderClientAreas) {
				base.UpDownBaseDrawButton (g, bounds, top, state);
				return;
			}
			VisualStyleElement element;
			if (top)
				switch (state) {
				case PushButtonState.Disabled:
					element = VisualStyleElement.Spin.Up.Disabled;
					break;
				case PushButtonState.Pressed:
					element = VisualStyleElement.Spin.Up.Pressed;
					break;
				case PushButtonState.Hot:
					element = VisualStyleElement.Spin.Up.Hot;
					break;
				default:
					element = VisualStyleElement.Spin.Up.Normal;
					break;
				}
			else
				switch (state) {
				case PushButtonState.Disabled:
					element = VisualStyleElement.Spin.Down.Disabled;
					break;
				case PushButtonState.Pressed:
					element = VisualStyleElement.Spin.Down.Pressed;
					break;
				case PushButtonState.Hot:
					element = VisualStyleElement.Spin.Down.Hot;
					break;
				default:
					element = VisualStyleElement.Spin.Down.Normal;
					break;
				}
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.UpDownBaseDrawButton (g, bounds, top, state);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (g, bounds);
		}
		public override bool UpDownBaseHasHotButtonStyle {
			get {
				if (!RenderClientAreas)
					return base.UpDownBaseHasHotButtonStyle;
				return true;
			}
		}
		#endregion
		#endregion

		static bool AreEqual (VisualStyleElement value1, VisualStyleElement value2)
		{
			return
				value1.ClassName == value1.ClassName &&
				value1.Part == value2.Part &&
				value1.State == value2.State;
		}

		#region Measurement device context
		static Control control;
		static IDeviceContext GetMeasurementDeviceContext ()
		{
			if (control == null)
				control = new Control ();
			return control.CreateGraphics ();
		}
		static void ReleaseMeasurementDeviceContext (IDeviceContext dc)
		{
			dc.Dispose ();
		}
		#endregion
	}
}