/// <include file='doc\GroupBoxRenderer.uex' path='docs/doc[@for="GroupBoxRenderer.IsBackgroundPartiallyTransparent"]/*' />
 /// <devdoc>
 ///    <para>
 ///       Returns true if the background corresponding to the given state is partially transparent, else false.
 ///    </para>
 /// </devdoc>
 public static bool IsBackgroundPartiallyTransparent(GroupBoxState state) {
    if (RenderWithVisualStyles) {
        InitializeRenderer((int)state);
        return visualStyleRenderer.IsBackgroundPartiallyTransparent();
    }
    else {
        return false; //for downlevel, this is false
    }
 }
 private static Color DefaultTextColor(GroupBoxState state)
 {
     if (RenderWithVisualStyles)
     {
         InitializeRenderer((int) state);
         return visualStyleRenderer.GetColor(ColorProperty.TextColor);
     }
     return SystemColors.ControlText;
 }
 public static void DrawGroupBox(Graphics g, Rectangle bounds, string groupBoxText, Font font, Color textColor, TextFormatFlags flags, GroupBoxState state)
 {
     if (RenderWithVisualStyles)
     {
         DrawThemedGroupBoxWithText(g, bounds, groupBoxText, font, textColor, flags, state);
     }
     else
     {
         DrawUnthemedGroupBoxWithText(g, bounds, groupBoxText, font, textColor, flags, state);
     }
 }
 public static void DrawGroupBox(Graphics g, Rectangle bounds, GroupBoxState state)
 {
     if (RenderWithVisualStyles)
     {
         DrawThemedGroupBoxNoText(g, bounds, state);
     }
     else
     {
         DrawUnthemedGroupBoxNoText(g, bounds, state);
     }
 }
Beispiel #5
0
		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;
				}

				if (groupBoxText == String.Empty)
					vsr.DrawBackground (g, bounds);
				else
					vsr.DrawBackgroundExcludingArea (g, new_bounds, new Rectangle (bounds.Left + 9, bounds.Top, font_size.Width - 3, font_size.Height));

				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), bounds.Width, bounds.Height - (int)(font_size.Height / 2));
				
				// 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) {
					if (textColor == Color.Empty)
						textColor = state == GroupBoxState.Normal ? SystemColors.ControlText :
							SystemColors.GrayText;
					TextRenderer.DrawText (g, groupBoxText, font, new Point (bounds.Left + 8, bounds.Top), textColor, flags);
				}
			}
		}
Beispiel #6
0
		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 ();
		}
        /// <summary>
        ///     Draws an un-themed GroupBox with a text label.
        ///     Variation of the logic in GroupBox.DrawGroupBox().
        /// </summary>
        /// <internalonly/>
        private static void DrawUnthemedGroupBoxWithText(Graphics g, Rectangle bounds, string groupBoxText, Font font, Color textColor, TextFormatFlags flags, GroupBoxState state) {
            // Calculate text area, and render text inside it
            Rectangle textBounds = bounds;

            textBounds.Width -= textOffset;
            Size measuredBounds = TextRenderer.MeasureText(g, groupBoxText, font, new Size(textBounds.Width, textBounds.Height), flags);
            textBounds.Width = measuredBounds.Width;
            textBounds.Height = measuredBounds.Height;

            if ((flags & TextFormatFlags.Right) == TextFormatFlags.Right) {
                textBounds.X = bounds.Right - textBounds.Width - textOffset;
            }
            else {
                textBounds.X += textOffset;
            }

            TextRenderer.DrawText(g, groupBoxText, font, textBounds, textColor, flags);

            // Pad text area to stop background from touching text
            if (textBounds.Width > 0)
                textBounds.Inflate(2, 0);

            Pen light = new Pen(SystemColors.ControlLight);
            Pen dark = new Pen(SystemColors.ControlDark);

            int boxTop = bounds.Top + font.Height / 2;
            
            // left
            g.DrawLine(light, bounds.Left + 1, boxTop, bounds.Left + 1, bounds.Height - 1);
            g.DrawLine(dark, bounds.Left, boxTop - 1, bounds.Left, bounds.Height - 2);

            // bottom
            g.DrawLine(light, bounds.Left, bounds.Height - 1, bounds.Width, bounds.Height - 1);
            g.DrawLine(dark, bounds.Left, bounds.Height - 2, bounds.Width - 1, bounds.Height - 2);

            // top-left
            g.DrawLine(light, bounds.Left + 1, boxTop, textBounds.X - 2, boxTop);
            g.DrawLine(dark, bounds.Left, boxTop - 1, textBounds.X - 3, boxTop - 1);
            
            // top-right
            g.DrawLine(light, textBounds.X + textBounds.Width + 1, boxTop, bounds.Width - 1, boxTop);
            g.DrawLine(dark, textBounds.X + textBounds.Width + 2, boxTop - 1, bounds.Width - 2, boxTop - 1);
            
            // right
            g.DrawLine(light, bounds.Width - 1, boxTop, bounds.Width - 1, bounds.Height - 1);
            g.DrawLine(dark, bounds.Width - 2, boxTop - 1, bounds.Width - 2, bounds.Height - 2);

            light.Dispose();
            dark.Dispose();
        }
        /// <summary>
        ///     Draws an un-themed GroupBox with no text label.
        /// </summary>
        /// <internalonly/>
        private static void DrawUnthemedGroupBoxNoText(Graphics g, Rectangle bounds, GroupBoxState state) {
            Color backColor = SystemColors.Control;         
            Pen light = new Pen(ControlPaint.Light(backColor, 1.0f));
            Pen dark = new Pen(ControlPaint.Dark(backColor, 0f));
            try {
                // left
                g.DrawLine(light, bounds.Left + 1, bounds.Top + 1, bounds.Left + 1, bounds.Height - 1);
                g.DrawLine(dark, bounds.Left, bounds.Top + 1, bounds.Left, bounds.Height - 2);

                // bottom
                g.DrawLine(light, bounds.Left, bounds.Height - 1, bounds.Width - 1, bounds.Height - 1);
                g.DrawLine(dark, bounds.Left, bounds.Height - 2, bounds.Width - 1, bounds.Height - 2);

                // top
                g.DrawLine(light, bounds.Left + 1, bounds.Top + 1, bounds.Width - 1, bounds.Top + 1);
                g.DrawLine(dark, bounds.Left, bounds.Top, bounds.Width - 2, bounds.Top);
                
                // right
                g.DrawLine(light, bounds.Width - 1, bounds.Top, bounds.Width - 1, bounds.Height - 1);
                g.DrawLine(dark, bounds.Width - 2, bounds.Top, bounds.Width - 2, bounds.Height - 2);
            }
            finally {
                if (light != null) {
                    light.Dispose();
                }
                if (dark != null) {
                    dark.Dispose();
                }
            }
        }
        /// <summary>
        ///     Draws a themed GroupBox with a text label.
        /// </summary>
        /// <internalonly/>
        private static void DrawThemedGroupBoxWithText(Graphics g, Rectangle bounds, string groupBoxText, Font font, Color textColor, TextFormatFlags flags, GroupBoxState state) {
            InitializeRenderer((int)state);

            // Calculate text area, and render text inside it
            Rectangle textBounds = bounds;

            textBounds.Width -= 2 * boxHeaderWidth;
            Size measuredBounds = TextRenderer.MeasureText(g, groupBoxText, font, new Size(textBounds.Width, textBounds.Height), flags);
            textBounds.Width = measuredBounds.Width;
            textBounds.Height = measuredBounds.Height;

            if ((flags & TextFormatFlags.Right) == TextFormatFlags.Right) {
                textBounds.X = bounds.Right - textBounds.Width - boxHeaderWidth + 1;  // +1 to account for the margin built in the MeasureText result
            }
            else {
                textBounds.X += boxHeaderWidth - 1;                                   // -1 to account for the margin built in the MeasureText result
            }

            TextRenderer.DrawText(g, groupBoxText, font, textBounds, textColor, flags);

            // Calculate area for background box
            Rectangle boxBounds = bounds;
            boxBounds.Y += font.Height / 2;
            boxBounds.Height -= font.Height / 2;

            // Break box into three segments, that don't overlap the text area
            Rectangle clipLeft   = boxBounds;
            Rectangle clipMiddle = boxBounds;
            Rectangle clipRight  = boxBounds;

            clipLeft.Width = boxHeaderWidth;
            clipMiddle.Width = Math.Max(0, textBounds.Width - 3);  // -3 to account for the margin built in the MeasureText result
            if ((flags & TextFormatFlags.Right) == TextFormatFlags.Right)
            {
                clipLeft.X = boxBounds.Right - boxHeaderWidth;
                clipMiddle.X = clipLeft.Left - clipMiddle.Width;
                clipRight.Width = clipMiddle.X - boxBounds.X;
            }
            else
            {
                clipMiddle.X = clipLeft.Right;
                clipRight.X = clipMiddle.Right;
                clipRight.Width = boxBounds.Right - clipRight.X;
            }
            clipMiddle.Y = textBounds.Bottom;
            clipMiddle.Height -= (textBounds.Bottom - boxBounds.Top);
            
            Debug.Assert(textBounds.Y <= boxBounds.Y, "if text below box, need to render area of box above text");

            // Render clipped portion of background in each segment
            visualStyleRenderer.DrawBackground(g, boxBounds, clipLeft);
            visualStyleRenderer.DrawBackground(g, boxBounds, clipMiddle);
            visualStyleRenderer.DrawBackground(g, boxBounds, clipRight);
        }
 private static void DrawUnthemedGroupBoxNoText(Graphics g, Rectangle bounds, GroupBoxState state)
 {
     Color control = SystemColors.Control;
     Pen pen = new Pen(ControlPaint.Light(control, 1f));
     Pen pen2 = new Pen(ControlPaint.Dark(control, 0f));
     try
     {
         g.DrawLine(pen, (int) (bounds.Left + 1), (int) (bounds.Top + 1), (int) (bounds.Left + 1), (int) (bounds.Height - 1));
         g.DrawLine(pen2, bounds.Left, bounds.Top + 1, bounds.Left, bounds.Height - 2);
         g.DrawLine(pen, bounds.Left, bounds.Height - 1, bounds.Width - 1, bounds.Height - 1);
         g.DrawLine(pen2, bounds.Left, bounds.Height - 2, bounds.Width - 1, bounds.Height - 2);
         g.DrawLine(pen, (int) (bounds.Left + 1), (int) (bounds.Top + 1), (int) (bounds.Width - 1), (int) (bounds.Top + 1));
         g.DrawLine(pen2, bounds.Left, bounds.Top, bounds.Width - 2, bounds.Top);
         g.DrawLine(pen, bounds.Width - 1, bounds.Top, bounds.Width - 1, bounds.Height - 1);
         g.DrawLine(pen2, bounds.Width - 2, bounds.Top, bounds.Width - 2, bounds.Height - 2);
     }
     finally
     {
         if (pen != null)
         {
             pen.Dispose();
         }
         if (pen2 != null)
         {
             pen2.Dispose();
         }
     }
 }
Beispiel #11
0
		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);
		}
 private static void DrawThemedGroupBoxWithText(Graphics g, Rectangle bounds, string groupBoxText, Font font, Color textColor, TextFormatFlags flags, GroupBoxState state)
 {
     InitializeRenderer((int) state);
     Rectangle rectangle = bounds;
     rectangle.Width -= 14;
     Size size = TextRenderer.MeasureText(g, groupBoxText, font, new Size(rectangle.Width, rectangle.Height), flags);
     rectangle.Width = size.Width;
     rectangle.Height = size.Height;
     if ((flags & TextFormatFlags.Right) == TextFormatFlags.Right)
     {
         rectangle.X = ((bounds.Right - rectangle.Width) - 7) + 1;
     }
     else
     {
         rectangle.X += 6;
     }
     TextRenderer.DrawText(g, groupBoxText, font, rectangle, textColor, flags);
     Rectangle rectangle2 = bounds;
     rectangle2.Y += font.Height / 2;
     rectangle2.Height -= font.Height / 2;
     Rectangle clipRectangle = rectangle2;
     Rectangle rectangle4 = rectangle2;
     Rectangle rectangle5 = rectangle2;
     clipRectangle.Width = 7;
     rectangle4.Width = Math.Max(0, rectangle.Width - 3);
     if ((flags & TextFormatFlags.Right) == TextFormatFlags.Right)
     {
         clipRectangle.X = rectangle2.Right - 7;
         rectangle4.X = clipRectangle.Left - rectangle4.Width;
         rectangle5.Width = rectangle4.X - rectangle2.X;
     }
     else
     {
         rectangle4.X = clipRectangle.Right;
         rectangle5.X = rectangle4.Right;
         rectangle5.Width = rectangle2.Right - rectangle5.X;
     }
     rectangle4.Y = rectangle.Bottom;
     rectangle4.Height -= rectangle.Bottom - rectangle2.Top;
     visualStyleRenderer.DrawBackground(g, rectangle2, clipRectangle);
     visualStyleRenderer.DrawBackground(g, rectangle2, rectangle4);
     visualStyleRenderer.DrawBackground(g, rectangle2, rectangle5);
 }
 public static bool IsBackgroundPartiallyTransparent(GroupBoxState state)
 {
     if (RenderWithVisualStyles)
     {
         InitializeRenderer((int) state);
         return visualStyleRenderer.IsBackgroundPartiallyTransparent();
     }
     return false;
 }
 private static void DrawUnthemedGroupBoxWithText(Graphics g, Rectangle bounds, string groupBoxText, Font font, Color textColor, TextFormatFlags flags, GroupBoxState state)
 {
     Rectangle rectangle = bounds;
     rectangle.Width -= 8;
     Size size = TextRenderer.MeasureText(g, groupBoxText, font, new Size(rectangle.Width, rectangle.Height), flags);
     rectangle.Width = size.Width;
     rectangle.Height = size.Height;
     if ((flags & TextFormatFlags.Right) == TextFormatFlags.Right)
     {
         rectangle.X = (bounds.Right - rectangle.Width) - 8;
     }
     else
     {
         rectangle.X += 8;
     }
     TextRenderer.DrawText(g, groupBoxText, font, rectangle, textColor, flags);
     if (rectangle.Width > 0)
     {
         rectangle.Inflate(2, 0);
     }
     Pen pen = new Pen(SystemColors.ControlLight);
     Pen pen2 = new Pen(SystemColors.ControlDark);
     int num = bounds.Top + (font.Height / 2);
     g.DrawLine(pen, bounds.Left + 1, num, bounds.Left + 1, bounds.Height - 1);
     g.DrawLine(pen2, bounds.Left, num - 1, bounds.Left, bounds.Height - 2);
     g.DrawLine(pen, bounds.Left, bounds.Height - 1, bounds.Width, bounds.Height - 1);
     g.DrawLine(pen2, bounds.Left, bounds.Height - 2, bounds.Width - 1, bounds.Height - 2);
     g.DrawLine(pen, bounds.Left + 1, num, rectangle.X - 2, num);
     g.DrawLine(pen2, bounds.Left, num - 1, rectangle.X - 3, num - 1);
     g.DrawLine(pen, (rectangle.X + rectangle.Width) + 1, num, bounds.Width - 1, num);
     g.DrawLine(pen2, (int) ((rectangle.X + rectangle.Width) + 2), (int) (num - 1), (int) (bounds.Width - 2), (int) (num - 1));
     g.DrawLine(pen, bounds.Width - 1, num, bounds.Width - 1, bounds.Height - 1);
     g.DrawLine(pen2, (int) (bounds.Width - 2), (int) (num - 1), (int) (bounds.Width - 2), (int) (bounds.Height - 2));
     pen.Dispose();
     pen2.Dispose();
 }
Beispiel #15
0
		public static void DrawGroupBox (Graphics g, Rectangle bounds, GroupBoxState state)
		{
			DrawGroupBox (g, bounds, String.Empty, null, Color.Empty, TextFormatFlags.Default, state);
		}
Beispiel #16
0
		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);
		}
 /// <include file='doc\GroupBoxRenderer.uex' path='docs/doc[@for="GroupBoxRenderer.DrawGroupBox1"]/*' />
 /// <devdoc>
 ///    <para>
 ///       Renders a GroupBox control. Uses the text color specified by the theme.
 ///    </para>
 /// </devdoc>
 public static void DrawGroupBox(Graphics g, Rectangle bounds, string groupBoxText, Font font, GroupBoxState state) {
     DrawGroupBox(g, bounds, groupBoxText, font, TextFormatFlags.Top | TextFormatFlags.Left, state);
 }
 /// <summary>
 ///     Draws a themed GroupBox with no text label.
 /// </summary>
 /// <internalonly/>
 private static void DrawThemedGroupBoxNoText(Graphics g, Rectangle bounds, GroupBoxState state) {
     InitializeRenderer((int)state);
     visualStyleRenderer.DrawBackground(g, bounds);
 }
Beispiel #19
0
 /// <summary>
 ///    <para>
 ///       Renders a GroupBox control.
 ///    </para>
 /// </summary>
 public static void DrawGroupBox(Graphics g, Rectangle bounds, string groupBoxText, Font font, Color textColor, GroupBoxState state)
 {
     DrawGroupBox(g, bounds, groupBoxText, font, textColor, TextFormatFlags.Top | TextFormatFlags.Left, state);
 }