好吧,伙计们,我想通了!只需缩小边界即可考虑笔的宽度.我有点知道这就是我只是想知道是否有办法在路径内部画一条线的答案.这很好用.
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); }