visual studio rectangulo rectangle dibujar c# gdi+ rounded-corners

c# - studio - Cómo dibujar un rectángulo redondeado con un borde de ancho variable dentro de límites específicos



draw rectangle visual studio (1)

Tengo un método que dibuja un rectángulo redondeado con un borde. El borde puede tener cualquier ancho, por lo que el problema que tengo es que el borde se extiende más allá de los límites dados cuando es grueso porque se dibuja desde el centro de una ruta.

¿Cómo incluiría el ancho del borde para que encaje perfectamente en los límites dados?

Aquí está el código que estoy usando para dibujar el rectángulo redondeado.

private void DrawRoundedRectangle(Graphics gfx, Rectangle Bounds, int CornerRadius, Pen DrawPen, Color FillColor) { GraphicsPath gfxPath = new GraphicsPath(); DrawPen.EndCap = DrawPen.StartCap = LineCap.Round; gfxPath.AddArc(Bounds.X, Bounds.Y, CornerRadius, CornerRadius, 180, 90); gfxPath.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y, CornerRadius, CornerRadius, 270, 90); gfxPath.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 0, 90); gfxPath.AddArc(Bounds.X, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90); gfxPath.CloseAllFigures(); gfx.FillPath(new SolidBrush(FillColor), gfxPath); gfx.DrawPath(DrawPen, gfxPath); }


Muy bien chicos, lo he descubierto! Solo tiene que reducir los límites para tener en cuenta el ancho de la pluma. Sabía que esta era la respuesta. Me preguntaba si había una forma de trazar una línea en el interior de un camino. Aunque esto funciona bien.

private void DrawRoundedRectangle(Graphics gfx, Rectangle Bounds, int CornerRadius, Pen DrawPen, Color FillColor) { int strokeOffset = Convert.ToInt32(Math.Ceiling(DrawPen.Width)); Bounds = Rectangle.Inflate(Bounds, -strokeOffset, -strokeOffset); DrawPen.EndCap = DrawPen.StartCap = LineCap.Round; GraphicsPath gfxPath = new GraphicsPath(); gfxPath.AddArc(Bounds.X, Bounds.Y, CornerRadius, CornerRadius, 180, 90); gfxPath.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y, CornerRadius, CornerRadius, 270, 90); gfxPath.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 0, 90); gfxPath.AddArc(Bounds.X, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90); gfxPath.CloseAllFigures(); gfx.FillPath(new SolidBrush(FillColor), gfxPath); gfx.DrawPath(DrawPen, gfxPath); }