用C#轻松画出空心圆环形状的任何方法

cks*_*ubs 4 c#

所以就像一个graphics.FillEllipse,但中间有一个洞.我需要通过在它们周围放一个环来突出显示一些圆形图标,并且由于较大程序的限制,很难/不可能简单地将FillEllipse放在它们下面以使它看起来像是一个洞.

小智 16

// Create a brush
SolidBrush b = new SolidBrush(Color.Blue);

// Clear your Graphics object (defined externally)
gfx.Clear(Color.White);

// You need a path for the outer and inner circles
GraphicsPath path1 = new GraphicsPath();
GraphicsPath path2 = new GraphicsPath();

// Define the paths (where X, Y, and D are chosen externally)
path1.AddEllipse((float)(X - D / 2), (float)(Y - D / 2), (float)D, (float)D);
path2.AddEllipse((float)(X - D / 4), (float)(Y - D / 4), (float)(D / 2), (float)(D / 2));

// Create a region from the Outer circle.
Region region = new Region(path1);

// Exclude the Inner circle from the region
region.Exclude(path2);

// Draw the region to your Graphics object
gfx.FillRegion(b, region);
Run Code Online (Sandbox Code Playgroud)


Nei*_*ell 14

使用GDI +,您可以绘制一个笔宽较高的圆圈,使其看起来像一个甜甜圈.中心没有任何东西,所以你将能够看透它.