2009-01-02 Ivan N. Zlatev <contact@i-nz.net>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ThemeVisualStyles.cs
index 5437a7ed46c8b5c84f1b0f65e8da64b9394570e6..33d9b6662adcfc1932cff436467deec7395e4618 100644 (file)
@@ -25,6 +25,7 @@
 //     Ernesto Carrea, equistango@gmail.com
 
 using System.Drawing;
+using System.Drawing.Drawing2D;
 using System.Windows.Forms.VisualStyles;
 
 namespace System.Windows.Forms
@@ -38,6 +39,38 @@ namespace System.Windows.Forms
        /// </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)
                {
@@ -74,7 +107,8 @@ namespace System.Windows.Forms
                #region Button 2.0
                public override void DrawButtonBackground (Graphics g, Button button, Rectangle clipArea)
                {
-                       if (!button.UseVisualStyleBackColor) {
+                       if (!RenderClientAreas ||
+                               !button.UseVisualStyleBackColor) {
                                base.DrawButtonBackground (g, button, clipArea);
                                return;
                        }
@@ -125,11 +159,102 @@ namespace System.Windows.Forms
                        }
                }
                #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);
+#if NET_2_0
+                       switch (comboBox.FlatStyle) {
+                       case FlatStyle.Flat:
+                       case FlatStyle.Popup:
+                               return base.ComboBoxDropDownButtonHasHotElementStyle (comboBox);
+                       }
+#endif
+                       return true;
+               }
+               static bool ComboBoxShouldPaintBackground (ComboBox comboBox)
+               {
+                       if (comboBox.DropDownStyle == ComboBoxStyle.Simple)
+                               return false;
+#if NET_2_0
+                       switch (comboBox.FlatStyle) {
+                       case FlatStyle.Flat:
+                       case FlatStyle.Popup:
+                               return false;
+                       }
+#endif 
+                       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 ((state & ButtonState.Flat) == ButtonState.Flat ||
+                       if (!RenderClientAreas ||
+                               (state & ButtonState.Flat) == ButtonState.Flat ||
                                (state & ButtonState.Checked) == ButtonState.Checked) {
                                base.CPDrawButton (dc, rectangle, state);
                                return;
@@ -151,7 +276,8 @@ namespace System.Windows.Forms
                #region DrawCaptionButton
                public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state)
                {
-                       if ((state & ButtonState.Flat) == ButtonState.Flat ||
+                       if (!RenderClientAreas ||
+                               (state & ButtonState.Flat) == ButtonState.Flat ||
                                (state & ButtonState.Checked) == ButtonState.Checked) {
                                base.CPDrawCaptionButton (graphics, rectangle, button, state);
                                return;
@@ -207,7 +333,8 @@ namespace System.Windows.Forms
                #region DrawCheckBox
                public override void CPDrawCheckBox (Graphics dc, Rectangle rectangle, ButtonState state)
                {
-                       if ((state & ButtonState.Flat) == ButtonState.Flat) {
+                       if (!RenderClientAreas ||
+                               (state & ButtonState.Flat) == ButtonState.Flat) {
                                base.CPDrawCheckBox (dc, rectangle, state);
                                return;
                        }
@@ -236,7 +363,8 @@ namespace System.Windows.Forms
                #region DrawComboButton
                public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state)
                {
-                       if ((state & ButtonState.Flat) == ButtonState.Flat ||
+                       if (!RenderClientAreas ||
+                               (state & ButtonState.Flat) == ButtonState.Flat ||
                                (state & ButtonState.Checked) == ButtonState.Checked) {
                                base.CPDrawComboButton (graphics, rectangle, state);
                                return;
@@ -258,7 +386,8 @@ namespace System.Windows.Forms
                #region DrawMixedCheckBox
                public override void CPDrawMixedCheckBox (Graphics dc, Rectangle rectangle, ButtonState state)
                {
-                       if ((state & ButtonState.Flat) == ButtonState.Flat) {
+                       if (!RenderClientAreas ||
+                               (state & ButtonState.Flat) == ButtonState.Flat) {
                                base.CPDrawMixedCheckBox (dc, rectangle, state);
                                return;
                        }
@@ -287,7 +416,8 @@ namespace System.Windows.Forms
                #region DrawRadioButton
                public override void CPDrawRadioButton (Graphics dc, Rectangle rectangle, ButtonState state)
                {
-                       if ((state & ButtonState.Flat) == ButtonState.Flat) {
+                       if (!RenderClientAreas ||
+                               (state & ButtonState.Flat) == ButtonState.Flat) {
                                base.CPDrawRadioButton (dc, rectangle, state);
                                return;
                        }
@@ -316,7 +446,8 @@ namespace System.Windows.Forms
                #region DrawScrollButton
                public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state)
                {
-                       if ((state & ButtonState.Flat) == ButtonState.Flat ||
+                       if (!RenderClientAreas ||
+                               (state & ButtonState.Flat) == ButtonState.Flat ||
                                (state & ButtonState.Checked) == ButtonState.Checked) {
                                base.CPDrawScrollButton (dc, area, type, state);
                                return;
@@ -371,271 +502,711 @@ namespace System.Windows.Forms
                }
                #endregion
                #endregion
-               #region Managed windows
-               [MonoTODO("When other VisualStyles implementations are supported, check if the visual style elements are defined.")]
-               [MonoTODO("When the rest of the MDI code is fixed, make sure minimized windows are painted correctly,restrict the caption text drawing area to exclude the title buttons and handle the title bar height correctly.")]
-               public override void DrawManagedWindowDecorations (Graphics dc, Rectangle clip, InternalWindowManager wm)
+#if NET_2_0
+               #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
+#endif
+               #region DateTimePicker
+               #region Border
+               protected override void DateTimePickerDrawBorder (DateTimePicker dateTimePicker, Graphics g, Rectangle clippingArea)
                {
-                       if (!wm.HasBorders || (wm.Form.IsMdiChild && wm.IsMaximized))
+                       if (!RenderClientAreas) {
+                               base.DateTimePickerDrawBorder (dateTimePicker, g, clippingArea);
                                return;
+                       }
                        VisualStyleElement element;
-                       #region Title bar background
-                       #region Select caption visual style element
-                       if (wm.IsToolWindow)
-                               #region Small window
-                               switch (wm.form.window_state) {
-                               case FormWindowState.Minimized:
-                                       if (!wm.Form.Enabled)
-                                               element = VisualStyleElement.Window.SmallMinCaption.Disabled;
-                                       else if (wm.IsActive)
-                                               element = VisualStyleElement.Window.SmallMinCaption.Active;
-                                       else
-                                               element = VisualStyleElement.Window.SmallMinCaption.Inactive;
-                                       break;
-                               case FormWindowState.Maximized:
-                                       if (!wm.Form.Enabled)
-                                               element = VisualStyleElement.Window.SmallMaxCaption.Disabled;
-                                       else if (wm.IsActive)
-                                               element = VisualStyleElement.Window.SmallMaxCaption.Active;
-                                       else
-                                               element = VisualStyleElement.Window.SmallMaxCaption.Inactive;
-                                       break;
-                               default:
-                                       if (!wm.Form.Enabled)
-                                               element = VisualStyleElement.Window.SmallCaption.Disabled;
-                                       else if (wm.IsActive)
-                                               element = VisualStyleElement.Window.SmallCaption.Active;
-                                       else
-                                               element = VisualStyleElement.Window.SmallCaption.Inactive;
-                                       break;
-                               }
-                               #endregion
+                       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
-                               #region Normal window
-                               switch (wm.form.window_state) {
-                               case FormWindowState.Minimized:
-                                       if (!wm.Form.Enabled)
-                                               element = VisualStyleElement.Window.MinCaption.Disabled;
-                                       else if (wm.IsActive)
-                                               element = VisualStyleElement.Window.MinCaption.Active;
-                                       else
-                                               element = VisualStyleElement.Window.MinCaption.Inactive;
-                                       break;
-                               case FormWindowState.Maximized:
-                                       if (!wm.Form.Enabled)
-                                               element = VisualStyleElement.Window.MaxCaption.Disabled;
-                                       else if (wm.IsActive)
-                                               element = VisualStyleElement.Window.MaxCaption.Active;
-                                       else
-                                               element = VisualStyleElement.Window.MaxCaption.Inactive;
-                                       break;
-                               default:
-                                       if (!wm.Form.Enabled)
-                                               element = VisualStyleElement.Window.Caption.Disabled;
-                                       else if (wm.IsActive)
-                                               element = VisualStyleElement.Window.Caption.Active;
-                                       else
-                                               element = VisualStyleElement.Window.Caption.Inactive;
-                                       break;
-                               }
-                               #endregion
-                       #endregion
-                       VisualStyleRenderer renderer = new VisualStyleRenderer (element);
-                       Rectangle title_bar_rectangle = new Rectangle (
-                               0,
-                               0,
-                               wm.Form.Width,
-                               renderer.GetPartSize (dc, ThemeSizeType.True).Height
-                       );
-                       Rectangle caption_text_area = title_bar_rectangle;
-                       renderer.DrawBackground (dc, title_bar_rectangle, clip);
-                       #endregion
-                       int border_width = ManagedWindowBorderWidth (wm);
-                       #region Icon
-                       if (!wm.IsToolWindow && wm.Form.FormBorderStyle != FormBorderStyle.FixedDialog
-#if NET_2_0
-                       && wm.Form.ShowIcon
-#endif
-                       ) {
-                               Rectangle icon_rectangle = new Rectangle (
-                                       border_width + 3,
-                                       border_width + 2,
-                                       wm.IconWidth,
-                                       wm.IconWidth);
-                               caption_text_area.X += icon_rectangle.Width;
-                               if (icon_rectangle.IntersectsWith (clip))
-                                       dc.DrawIcon (wm.Form.Icon, icon_rectangle);
-                       }
-                       #endregion
-                       #region Title bar buttons
-                       foreach (TitleButton button in wm.TitleButtons.AllButtons) {
-                               if (!button.Visible || !button.Rectangle.IntersectsWith (clip))
-                                       continue;
-                               new VisualStyleRenderer (GetCaptionButtonVisualStyleElement (button.Caption, button.State)).DrawBackground (dc, button.Rectangle, clip);
-                       }
-                       #endregion
-                       #region Borders
-                       if (wm.GetWindowState () == FormWindowState.Normal) {
-                               #region Left
-                               if (wm.IsToolWindow)
-                                       if (wm.IsActive)
-                                               element = VisualStyleElement.Window.SmallFrameLeft.Active;
-                                       else
-                                               element = VisualStyleElement.Window.SmallFrameLeft.Inactive;
+                               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
-                                       if (wm.IsActive)
-                                               element = VisualStyleElement.Window.FrameLeft.Active;
-                                       else
-                                               element = VisualStyleElement.Window.FrameLeft.Inactive;
-                               renderer = new VisualStyleRenderer (element);
+                                       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
+                                       wm.Form.Height - title_bar_rectangle.Bottom
                                        ), clip);
-                               #endregion
-                               #region Right
-                               if (wm.IsToolWindow)
-                                       if (wm.IsActive)
-                                               element = VisualStyleElement.Window.SmallFrameRight.Active;
-                                       else
-                                               element = VisualStyleElement.Window.SmallFrameRight.Inactive;
-                               else
-                                       if (wm.IsActive)
-                                               element = VisualStyleElement.Window.FrameRight.Active;
-                                       else
-                                               element = VisualStyleElement.Window.FrameRight.Inactive;
-
-                               renderer = new VisualStyleRenderer (element);
+                               renderer.SetParameters (right_border_element);
                                renderer.DrawBackground (dc, new Rectangle (
-                                       wm.form.Width - border_width,
+                                       wm.Form.Width - border_width,
                                        title_bar_rectangle.Bottom,
                                        border_width,
-                                       wm.form.Height - title_bar_rectangle.Bottom
+                                       wm.Form.Height - title_bar_rectangle.Bottom
                                        ), clip);
-                               #endregion
-                               #region Bottom
-                               if (wm.IsToolWindow)
-                                       if (wm.IsActive)
-                                               element = VisualStyleElement.Window.SmallFrameBottom.Active;
-                                       else
-                                               element = VisualStyleElement.Window.SmallFrameBottom.Inactive;
-                               else
-                                       if (wm.IsActive)
-                                               element = VisualStyleElement.Window.FrameBottom.Active;
-                                       else
-                                               element = VisualStyleElement.Window.FrameBottom.Inactive;
-
-                               renderer = new VisualStyleRenderer (element);
+                               renderer.SetParameters (bottom_border_element);
                                renderer.DrawBackground (dc, new Rectangle (
                                        0,
-                                       wm.form.Height - border_width,
-                                       wm.form.Width,
+                                       wm.Form.Height - border_width,
+                                       wm.Form.Width,
                                        border_width
                                        ), clip);
-                               #endregion
-                               caption_text_area.X += border_width;
-                       }
-                       #endregion
-                       #region Caption text
-                       string window_caption = wm.Form.Text;
-                       if (window_caption != null && window_caption.Length != 0 && caption_text_area.IntersectsWith (clip)) {
-                               StringFormat format = new StringFormat ();
-                               format.FormatFlags = StringFormatFlags.NoWrap;
-                               format.Trimming = StringTrimming.EllipsisCharacter;
-                               format.LineAlignment = StringAlignment.Center;
-                               dc.DrawString (
-                                       window_caption,
-                                       WindowBorderFont,
-                                       ThemeEngine.Current.ResPool.GetSolidBrush (Color.White),
-                                       caption_text_area,
-                                       format
-                               );
                        }
-                       #endregion
+                       return title_bar_rectangle;
                }
-               #endregion
-               #region ProgressBar
-               public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
+               static FormWindowState ManagedWindowGetWindowState (InternalWindowManager wm)
                {
-                       if (!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;
-#if NET_2_0
-                       draw_mode = (int)ctrl.Style;
-#endif
-                       switch (draw_mode) {
-#if NET_2_0
-                       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 % (double)ctrl.MarqueeAnimationSpeed / (double)ctrl.MarqueeAnimationSpeed;
-                               max_blocks = 5;
-                               start_pixel = client_area.X + (int)(client_area.Width * percent_done);
-                               goto default;
-#endif
-                       default: // Blocks
-                               int block_width = renderer.GetInteger (IntegerProperty.ProgressChunkSize);
-                               int first_pixel_outside_filled_area = ((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;
-                       }
+                       return wm.GetWindowState ();
                }
-               #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 bool ManagedWindowIsDisabled (InternalWindowManager wm)
+               {
+                       return !wm.Form.Enabled;
                }
-               static RadioButtonState GetRadioButtonState (RadioButton checkBox)
+               static bool ManagedWindowIsActive (InternalWindowManager wm)
                {
-                       if (checkBox.Checked) {
-                               if (!checkBox.Enabled)
-                                       return RadioButtonState.CheckedDisabled;
-                               else if (checkBox.Pressed)
+                       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;
+#if NET_2_0
+                       draw_mode = (int)ctrl.Style;
+#endif
+                       switch (draw_mode) {
+#if NET_2_0
+                       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 % (double)ctrl.MarqueeAnimationSpeed / (double)ctrl.MarqueeAnimationSpeed;
+                               max_blocks = 5;
+                               start_pixel = client_area.X + (int)(client_area.Width * percent_done);
+                               goto default;
+#endif
+                       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;
@@ -652,9 +1223,13 @@ namespace System.Windows.Forms
                }
                #endregion
                #region ScrollBar
-               [MonoTODO ("Enable the rest of the code when ScrollBar will be changed to supply the required information.")]
                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;
@@ -707,8 +1282,10 @@ namespace System.Windows.Forms
                                                element = VisualStyleElement.ScrollBar.ArrowButton.UpDisabled;
                                        else if (bar.firstbutton_state == ButtonState.Pushed)
                                                element = VisualStyleElement.ScrollBar.ArrowButton.UpPressed;
-                                       //else if (bar.firstbutton_entered)
-                                       //    element = VisualStyleElement.ScrollBar.ArrowButton.UpHot;
+                                       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);
@@ -719,8 +1296,10 @@ namespace System.Windows.Forms
                                                element = VisualStyleElement.ScrollBar.ArrowButton.DownDisabled;
                                        else if (bar.secondbutton_state == ButtonState.Pushed)
                                                element = VisualStyleElement.ScrollBar.ArrowButton.DownPressed;
-                                       //else if (bar.secondbutton_entered)
-                                       //    element = VisualStyleElement.ScrollBar.ArrowButton.DownHot;
+                                       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);
@@ -730,10 +1309,10 @@ namespace System.Windows.Forms
                                #region Thumb and grip
                                if (!bar.Enabled)
                                        element = VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled;
-                               //else if (bar.thumb_state == ButtonState.Pushed)
-                               //    element = VisualStyleElement.ScrollBar.ThumbButtonVertical.Pressed;
-                               //else if (bar.thumb_entered)
-                               //    element = VisualStyleElement.ScrollBar.ThumbButtonVertical.Hot;
+                               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);
@@ -741,8 +1320,10 @@ namespace System.Windows.Forms
 
                                if (bar.Enabled && bar.ThumbPos.Height >= 20) {
                                        element = VisualStyleElement.ScrollBar.GripperVertical.Normal;
-                                       renderer = new VisualStyleRenderer (element);
-                                       renderer.DrawBackground (dc, bar.ThumbPos, clip);
+                                       if (VisualStyleRenderer.IsElementDefined (element)) {
+                                               renderer = new VisualStyleRenderer (element);
+                                               renderer.DrawBackground (dc, bar.ThumbPos, clip);
+                                       }
                                }
                                #endregion
                        } else {
@@ -793,8 +1374,10 @@ namespace System.Windows.Forms
                                                element = VisualStyleElement.ScrollBar.ArrowButton.LeftDisabled;
                                        else if (bar.firstbutton_state == ButtonState.Pushed)
                                                element = VisualStyleElement.ScrollBar.ArrowButton.LeftPressed;
-                                       //else if (bar.firstbutton_entered)
-                                       //    element = VisualStyleElement.ScrollBar.ArrowButton.LeftHot;
+                                       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);
@@ -805,8 +1388,10 @@ namespace System.Windows.Forms
                                                element = VisualStyleElement.ScrollBar.ArrowButton.RightDisabled;
                                        else if (bar.secondbutton_state == ButtonState.Pushed)
                                                element = VisualStyleElement.ScrollBar.ArrowButton.RightPressed;
-                                       //else if (bar.secondbutton_entered)
-                                       //    element = VisualStyleElement.ScrollBar.ArrowButton.RightHot;
+                                       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);
@@ -816,10 +1401,10 @@ namespace System.Windows.Forms
                                #region Thumb and grip
                                if (!bar.Enabled)
                                        element = VisualStyleElement.ScrollBar.RightTrackHorizontal.Disabled;
-                               //else if (bar.thumb_state == ButtonState.Pushed)
-                               //    element = VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Pressed;
-                               //else if (bar.thumb_entered)
-                               //    element = VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Hot;
+                               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);
@@ -827,25 +1412,76 @@ namespace System.Windows.Forms
 
                                if (bar.Enabled && bar.ThumbPos.Height >= 20) {
                                        element = VisualStyleElement.ScrollBar.GripperHorizontal.Normal;
-                                       renderer = new VisualStyleRenderer (element);
-                                       renderer.DrawBackground (dc, bar.ThumbPos, clip);
+                                       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))
+                       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))
+                       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;
@@ -854,16 +1490,594 @@ namespace System.Windows.Forms
                }
                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))
+                       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
                [MonoTODO("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;
@@ -874,5 +2088,81 @@ namespace System.Windows.Forms
                        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
+
+#if NET_2_0
+               static bool AreEqual (VisualStyleElement value1, VisualStyleElement value2)
+               {
+                       return
+                               value1.ClassName == value1.ClassName &&
+                               value1.Part == value2.Part &&
+                               value1.State == value2.State;
+               }
+#endif
+               #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
        }
 }