如何在特定边界内绘制具有可变宽度边框的圆角矩形.边框可以是任何宽度,所以我遇到的问题是当边框比给定的边界更厚时边框会拉伸,因为它是从路径的中心绘制的。我怎样才能包括边框的宽度,使其完全符合给定的范围?这是我用来绘制圆角矩形的代码。privatevoidDrawRoundedRectangle(Graphicsgfx,RectangleBounds,intCornerRadius,PenDrawPen,ColorFillColor){GraphicsPathgfxPath=newGraphicsPath();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);gfx路径。CloseAllFigures();gfx.FillPath(newSolidBrush(FillColor),gfxPath);gfx.DrawPath(DrawPen,gfxPath);好的伙计们,我明白了!只需缩小边框以适应笔的宽度。我有点知道这是答案我只是想知道是否有办法在路径内画一条线。这很好用。以上就是C#学习教程:如何在特定边界内绘制一个可变宽度边框的圆角矩形。如果对大家有用,需要进一步了解C#学习教程,希望大家多多关注~Convert.ToInt32(Math.Ceiling(DrawPen.Width));Bounds=Rectangle.Inflate(Bounds,-strokeOffset,-strokeOffset);DrawPen.EndCap=DrawPen.StartCap=LineCap.Round;GraphicsPathgfxPath=newGraphicsPath();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(newSolidBrush(FillColor),gfxPath);gfx.DrawPath(DrawPen,gfxPath);}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如有转载请注明出处:
