C# make line height adjust to ellipse

2019-08-10 18:56发布

There is an ellipse drawn with the following code:

graphGraphics = e.Graphics;

graphGraphics.FillEllipse(new SolidBrush(Color.White), this.graphBoundries);
graphGraphics.DrawEllipse(graphPen, this.graphBoundries);

I have a line on this graph and it currently just passes right through it. I want to change the lines height to adjust to the ellipse's boundaries as follows so it wont pass through the ellipse:

http://i1379.photobucket.com/albums/ah134/fac7orx2/circlewithlinehelp_zps280d9e76.png

Does anyone know an algorithm to do this? Or maybe even how to just get the ellipse's boundaries and not just the rectangular boundaries?

1条回答
太酷不给撩
2楼-- · 2019-08-10 19:23

To expand on my comment, try something like this (untested) code:

graphGraphics = e.Graphics;

graphGraphics.FillEllipse(new SolidBrush(Color.White), this.graphBoundries);
graphGraphics.DrawEllipse(graphPen, this.graphBoundries);

GraphicsPath clipPath = new GraphicsPath();
clipPath.AddEllipse(this.graphBoundaries);

graphGraphics.SetClip(clipPath, CombineMode.Replace);

// draw your line
查看更多
登录 后发表回答