/// <summary> /// </summary> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="g"/> is <see langword="null"/>. /// </para> /// </exception> public void DrawRoundBorder(Graphics g, Rectangle bounds, NuGenControlState state, NuGenRoundRectangleStyle style) { if (g == null) { throw new ArgumentNullException("g"); } using (Pen pen = this.GetBorderPen(state)) { NuGenControlPaint.DrawRoundRectangle(g, pen, bounds, _roundRectangleRadius, style); } }
/// <summary> /// </summary> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="g"/> is <see langword="null"/>. /// </para> /// </exception> public void DrawRoundBackground(Graphics g, Rectangle bounds, NuGenControlState state, NuGenRoundRectangleStyle style) { if (g == null) { throw new ArgumentNullException("g"); } if (bounds.Width > 0 && bounds.Height > 0) { using (Brush brush = this.GetBackgroundBrush(bounds, state)) using (GraphicsPath gp = NuGenControlPaint.GetRoundRectangleGraphicsPath(bounds, _roundRectangleRadius, style)) { g.FillPath(brush, gp); } } }
/* * GetRoundRectangleGraphicsPath */ /// <summary> /// </summary> /// <exception cref="ArgumentException"> /// <para> /// <paramref name="radius"/> should be positive. /// </para> /// </exception> public static GraphicsPath GetRoundRectangleGraphicsPath(Rectangle rectangleBounds, Single radius, NuGenRoundRectangleStyle style) { /* * Verify input parameters. */ if (radius <= 0) { throw new ArgumentException(Properties.Resources.Argument_NotPositiveRadius); } GraphicsPath path = new GraphicsPath(); if (rectangleBounds.IsEmpty) { return path; } Single size = radius * 2f; switch (style) { case NuGenRoundRectangleStyle.TopRound: { path.AddArc(rectangleBounds.X, rectangleBounds.Y, size, size, 180, 90); path.AddArc(rectangleBounds.Right - size, rectangleBounds.Y, size, size, 270, 90); path.AddLine(RectBRCorner(rectangleBounds), RectBLCorner(rectangleBounds)); break; } case NuGenRoundRectangleStyle.BottomRound: { path.AddLine(RectTLCorner(rectangleBounds), RectTRCorner(rectangleBounds)); path.AddArc(rectangleBounds.Right - size, rectangleBounds.Bottom - size, size, size, 0, 90); path.AddArc(rectangleBounds.X, rectangleBounds.Bottom - size, size, size, 90, 90); break; } default: { path.AddArc(rectangleBounds.Left, rectangleBounds.Top, size, size, 180, 90); path.AddArc(rectangleBounds.Right - size, rectangleBounds.Top, size, size, 270, 90); path.AddArc(rectangleBounds.Right - size, rectangleBounds.Bottom - size, size, size, 0, 90); path.AddArc(rectangleBounds.Left, rectangleBounds.Bottom - size, size, size, 90, 90); break; } } path.CloseFigure(); return path; }
/* * FillRoundRectangle */ /// <summary> /// Fills a round rectangle on the specified graphics surface with the specified pen within the /// specified bounds and with the specified radius. /// </summary> /// <exception cref="ArgumentException"> /// <para> /// <paramref name="radius"/> should be positive. /// </para> /// </exception> /// <exception cref="ArgumentNullException"> /// <para><paramref name="g"/> is <see langword="null"/>.</para> /// -or- /// <para><paramref name="brush"/> is <see langword="null"/>.</para> /// </exception> public static void FillRoundRectangle(Graphics g, Brush brush, Rectangle rectangleBounds, Single radius, NuGenRoundRectangleStyle style) { if (g == null) { throw new ArgumentNullException("g"); } if (brush == null) { throw new ArgumentNullException("brush"); } using (GraphicsPath path = GetRoundRectangleGraphicsPath(rectangleBounds, radius, style)) { g.FillPath(brush, path); } }
/* * DrawRoundRectangle */ /// <summary> /// Draws a round rectangle on the specified graphics surface with the specified pen within the /// specified bounds and with the specified radius. /// </summary> /// <exception cref="ArgumentException"> /// <para> /// <paramref name="radius"/> should be positive. /// </para> /// </exception> /// <exception cref="ArgumentNullException"> /// <para><paramref name="g"/> is <see langword="null"/>.</para> /// -or- /// <para><paramref name="pen"/> is <see langword="null"/>.</para> /// </exception> public static void DrawRoundRectangle(Graphics g, Pen pen, Rectangle rectangleBounds, Single radius, NuGenRoundRectangleStyle style) { if (g == null) { throw new ArgumentNullException("g"); } if (pen == null) { throw new ArgumentNullException("pen"); } using (GraphicsPath path = NuGenControlPaint.GetRoundRectangleGraphicsPath(rectangleBounds, radius, style)) { g.DrawPath(pen, path); } }
/* * GetRoundRectangleGraphicsPath */ /// <summary> /// </summary> /// <exception cref="ArgumentException"> /// <para> /// <paramref name="radius"/> should be positive. /// </para> /// </exception> public static GraphicsPath GetRoundRectangleGraphicsPath(Rectangle rectangleBounds, Single radius, NuGenRoundRectangleStyle style) { /* * Verify input parameters. */ if (radius <= 0) { throw new ArgumentException(Properties.Resources.Argument_NotPositiveRadius); } GraphicsPath path = new GraphicsPath(); if (rectangleBounds.IsEmpty) { return(path); } Single size = radius * 2f; switch (style) { case NuGenRoundRectangleStyle.TopRound: { path.AddArc(rectangleBounds.X, rectangleBounds.Y, size, size, 180, 90); path.AddArc(rectangleBounds.Right - size, rectangleBounds.Y, size, size, 270, 90); path.AddLine(RectBRCorner(rectangleBounds), RectBLCorner(rectangleBounds)); break; } case NuGenRoundRectangleStyle.BottomRound: { path.AddLine(RectTLCorner(rectangleBounds), RectTRCorner(rectangleBounds)); path.AddArc(rectangleBounds.Right - size, rectangleBounds.Bottom - size, size, size, 0, 90); path.AddArc(rectangleBounds.X, rectangleBounds.Bottom - size, size, size, 90, 90); break; } default: { path.AddArc(rectangleBounds.Left, rectangleBounds.Top, size, size, 180, 90); path.AddArc(rectangleBounds.Right - size, rectangleBounds.Top, size, size, 270, 90); path.AddArc(rectangleBounds.Right - size, rectangleBounds.Bottom - size, size, size, 0, 90); path.AddArc(rectangleBounds.Left, rectangleBounds.Bottom - size, size, size, 90, 90); break; } } path.CloseFigure(); return(path); }