-//\r
-// GroupBoxRenderer.cs\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-// Copyright (c) 2006 Novell, Inc.\r
-//\r
-// Authors:\r
-// Jonathan Pobst (monkey@jpobst.com)\r
-//\r
-\r
-#if NET_2_0\r
-using System.Drawing;\r
-using System.Windows.Forms.VisualStyles;\r
-\r
-namespace System.Windows.Forms\r
-{\r
- public sealed class GroupBoxRenderer\r
- {\r
- private static bool always_use_visual_styles = false;\r
- \r
- #region Private Constructor\r
- private GroupBoxRenderer () { }\r
- #endregion\r
-\r
- #region Public Static Methods\r
- public static void DrawGroupBox (Graphics g, Rectangle bounds, GroupBoxState state)\r
- {\r
- DrawGroupBox (g, bounds, String.Empty, null, Color.Empty, TextFormatFlags.Default, state);\r
- }\r
-\r
- public static void DrawGroupBox (Graphics g, Rectangle bounds, string groupBoxText, Font font, GroupBoxState state)\r
- {\r
- DrawGroupBox (g, bounds, groupBoxText, font, Color.Empty, TextFormatFlags.Default, state);\r
- }\r
-\r
- public static void DrawGroupBox (Graphics g, Rectangle bounds, string groupBoxText, Font font, Color textColor, GroupBoxState state)\r
- {\r
- DrawGroupBox (g, bounds, groupBoxText, font, textColor, TextFormatFlags.Default, state);\r
- }\r
-\r
- public static void DrawGroupBox (Graphics g, Rectangle bounds, string groupBoxText, Font font, TextFormatFlags flags, GroupBoxState state)\r
- {\r
- DrawGroupBox (g, bounds, groupBoxText, font, Color.Empty, flags, state);\r
- }\r
-\r
- public static void DrawGroupBox (Graphics g, Rectangle bounds, string groupBoxText, Font font, Color textColor, TextFormatFlags flags, GroupBoxState state)\r
- {\r
- Size font_size = TextRenderer.MeasureText (groupBoxText, font);\r
-\r
- if (Application.RenderWithVisualStyles || always_use_visual_styles == true) {\r
- VisualStyleRenderer vsr;\r
- Rectangle new_bounds;\r
-\r
- switch (state) {\r
- case GroupBoxState.Normal:\r
- default:\r
- vsr = new VisualStyleRenderer (VisualStyleElement.Button.GroupBox.Normal);\r
- new_bounds = new Rectangle (bounds.Left, bounds.Top + (int)(font_size.Height / 2) - 1, bounds.Width, bounds.Height - (int)(font_size.Height / 2) + 1);\r
- break;\r
- case GroupBoxState.Disabled:\r
- vsr = new VisualStyleRenderer (VisualStyleElement.Button.GroupBox.Disabled);\r
- new_bounds = new Rectangle (bounds.Left, bounds.Top + (int)(font_size.Height / 2) - 2, bounds.Width, bounds.Height - (int)(font_size.Height / 2) + 2);\r
- break;\r
- }\r
-\r
- // Don't paint over the background where we are going to put the text\r
- Region old_clip = g.Clip;\r
- g.SetClip (new Rectangle (bounds.Left + 9, bounds.Top, font_size.Width - 3, font_size.Height), System.Drawing.Drawing2D.CombineMode.Exclude);\r
-\r
- if (groupBoxText == String.Empty)\r
- vsr.DrawBackground (g, bounds);\r
- else\r
- vsr.DrawBackground (g, new_bounds);\r
-\r
- g.Clip = old_clip;\r
-\r
- if (textColor == Color.Empty)\r
- textColor = vsr.GetColor (ColorProperty.TextColor);\r
-\r
- if (groupBoxText != String.Empty)\r
- TextRenderer.DrawText (g, groupBoxText, font, new Point (bounds.Left + 8, bounds.Top), textColor, flags);\r
- }\r
- else {\r
- // MS has a pretty big bug when rendering the non-visual styles group box. Instead of using the height\r
- // part of the bounds as height, they use it as the bottom, so the boxes are drawn in completely different\r
- // places. Rather than emulate this bug, we do it correctly. After googling for a while, I don't think\r
- // anyone has ever actually used this class for anything, so it should be fine. :)\r
- Rectangle new_bounds = new Rectangle (bounds.Left, bounds.Top + (int)(font_size.Height / 2) - 1, bounds.Width, bounds.Height - (int)(font_size.Height / 2) + 1);\r
- \r
- // Don't paint over the background where we are going to put the text\r
- Region old_clip = g.Clip;\r
- g.SetClip (new Rectangle (bounds.Left + 9, bounds.Top, font_size.Width - 3, font_size.Height), System.Drawing.Drawing2D.CombineMode.Exclude);\r
- \r
- ControlPaint.DrawBorder3D (g, new_bounds, Border3DStyle.Etched);\r
- \r
- g.Clip = old_clip;\r
-\r
- if (groupBoxText != String.Empty)\r
- TextRenderer.DrawText (g, groupBoxText, font, new Point (bounds.Left + 8, bounds.Top), textColor, flags);\r
- }\r
- }\r
-\r
- public static bool IsBackgroundPartiallyTransparent (GroupBoxState state)\r
- {\r
- if (!VisualStyleRenderer.IsSupported)\r
- return false;\r
-\r
- VisualStyleRenderer vsr;\r
-\r
- switch (state) {\r
- case GroupBoxState.Normal:\r
- default:\r
- vsr = new VisualStyleRenderer (VisualStyleElement.Button.GroupBox.Normal);\r
- break;\r
- case GroupBoxState.Disabled:\r
- vsr = new VisualStyleRenderer (VisualStyleElement.Button.GroupBox.Disabled);\r
- break;\r
- }\r
-\r
- return vsr.IsBackgroundPartiallyTransparent ();\r
- }\r
-\r
- public static void DrawParentBackground (Graphics g, Rectangle bounds, Control childControl)\r
- {\r
- if (!VisualStyleRenderer.IsSupported)\r
- return;\r
- \r
- VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.Button.GroupBox.Normal);\r
-\r
- vsr.DrawParentBackground (g, bounds, childControl);\r
- }\r
- #endregion\r
-\r
- #region Public Static Properties\r
- public static bool RenderMatchingApplicationState {\r
- get { return !always_use_visual_styles; }\r
- set { always_use_visual_styles = !value; }\r
- }\r
- #endregion\r
- }\r
-}\r
+//
+// GroupBoxRenderer.cs
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2006 Novell, Inc.
+//
+// Authors:
+// Jonathan Pobst (monkey@jpobst.com)
+//
+
+#if NET_2_0
+using System.Drawing;
+using System.Windows.Forms.VisualStyles;
+
+namespace System.Windows.Forms
+{
+ public sealed class GroupBoxRenderer
+ {
+ private static bool always_use_visual_styles = false;
+
+ #region Private Constructor
+ private GroupBoxRenderer () { }
+ #endregion
+
+ #region Public Static Methods
+ public static void DrawGroupBox (Graphics g, Rectangle bounds, GroupBoxState state)
+ {
+ DrawGroupBox (g, bounds, String.Empty, null, Color.Empty, TextFormatFlags.Default, state);
+ }
+
+ public static void DrawGroupBox (Graphics g, Rectangle bounds, string groupBoxText, Font font, GroupBoxState state)
+ {
+ DrawGroupBox (g, bounds, groupBoxText, font, Color.Empty, TextFormatFlags.Default, state);
+ }
+
+ public static void DrawGroupBox (Graphics g, Rectangle bounds, string groupBoxText, Font font, Color textColor, GroupBoxState state)
+ {
+ DrawGroupBox (g, bounds, groupBoxText, font, textColor, TextFormatFlags.Default, state);
+ }
+
+ public static void DrawGroupBox (Graphics g, Rectangle bounds, string groupBoxText, Font font, TextFormatFlags flags, GroupBoxState state)
+ {
+ DrawGroupBox (g, bounds, groupBoxText, font, Color.Empty, flags, state);
+ }
+
+ public static void DrawGroupBox (Graphics g, Rectangle bounds, string groupBoxText, Font font, Color textColor, TextFormatFlags flags, GroupBoxState state)
+ {
+ Size font_size = TextRenderer.MeasureText (groupBoxText, font);
+
+ if (Application.RenderWithVisualStyles || always_use_visual_styles == true) {
+ VisualStyleRenderer vsr;
+ Rectangle new_bounds;
+
+ switch (state) {
+ case GroupBoxState.Normal:
+ default:
+ vsr = new VisualStyleRenderer (VisualStyleElement.Button.GroupBox.Normal);
+ new_bounds = new Rectangle (bounds.Left, bounds.Top + (int)(font_size.Height / 2) - 1, bounds.Width, bounds.Height - (int)(font_size.Height / 2) + 1);
+ break;
+ case GroupBoxState.Disabled:
+ vsr = new VisualStyleRenderer (VisualStyleElement.Button.GroupBox.Disabled);
+ new_bounds = new Rectangle (bounds.Left, bounds.Top + (int)(font_size.Height / 2) - 2, bounds.Width, bounds.Height - (int)(font_size.Height / 2) + 2);
+ break;
+ }
+
+ // Don't paint over the background where we are going to put the text
+ Region old_clip = g.Clip;
+ g.SetClip (new Rectangle (bounds.Left + 9, bounds.Top, font_size.Width - 3, font_size.Height), System.Drawing.Drawing2D.CombineMode.Exclude);
+
+ if (groupBoxText == String.Empty)
+ vsr.DrawBackground (g, bounds);
+ else
+ vsr.DrawBackground (g, new_bounds);
+
+ g.Clip = old_clip;
+
+ if (textColor == Color.Empty)
+ textColor = vsr.GetColor (ColorProperty.TextColor);
+
+ if (groupBoxText != String.Empty)
+ TextRenderer.DrawText (g, groupBoxText, font, new Point (bounds.Left + 8, bounds.Top), textColor, flags);
+ }
+ else {
+ // MS has a pretty big bug when rendering the non-visual styles group box. Instead of using the height
+ // part of the bounds as height, they use it as the bottom, so the boxes are drawn in completely different
+ // places. Rather than emulate this bug, we do it correctly. After googling for a while, I don't think
+ // anyone has ever actually used this class for anything, so it should be fine. :)
+ Rectangle new_bounds = new Rectangle (bounds.Left, bounds.Top + (int)(font_size.Height / 2) - 1, bounds.Width, bounds.Height - (int)(font_size.Height / 2) + 1);
+
+ // Don't paint over the background where we are going to put the text
+ Region old_clip = g.Clip;
+ g.SetClip (new Rectangle (bounds.Left + 9, bounds.Top, font_size.Width - 3, font_size.Height), System.Drawing.Drawing2D.CombineMode.Exclude);
+
+ ControlPaint.DrawBorder3D (g, new_bounds, Border3DStyle.Etched);
+
+ g.Clip = old_clip;
+
+ if (groupBoxText != String.Empty)
+ TextRenderer.DrawText (g, groupBoxText, font, new Point (bounds.Left + 8, bounds.Top), textColor, flags);
+ }
+ }
+
+ public static bool IsBackgroundPartiallyTransparent (GroupBoxState state)
+ {
+ if (!VisualStyleRenderer.IsSupported)
+ return false;
+
+ VisualStyleRenderer vsr;
+
+ switch (state) {
+ case GroupBoxState.Normal:
+ default:
+ vsr = new VisualStyleRenderer (VisualStyleElement.Button.GroupBox.Normal);
+ break;
+ case GroupBoxState.Disabled:
+ vsr = new VisualStyleRenderer (VisualStyleElement.Button.GroupBox.Disabled);
+ break;
+ }
+
+ return vsr.IsBackgroundPartiallyTransparent ();
+ }
+
+ public static void DrawParentBackground (Graphics g, Rectangle bounds, Control childControl)
+ {
+ if (!VisualStyleRenderer.IsSupported)
+ return;
+
+ VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.Button.GroupBox.Normal);
+
+ vsr.DrawParentBackground (g, bounds, childControl);
+ }
+ #endregion
+
+ #region Public Static Properties
+ public static bool RenderMatchingApplicationState {
+ get { return !always_use_visual_styles; }
+ set { always_use_visual_styles = !value; }
+ }
+ #endregion
+ }
+}
#endif
\ No newline at end of file