C# make line height adjust to ellipse

瘦欲@ 提交于 2019-12-11 04:24:01

问题


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:


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


来源:https://stackoverflow.com/questions/27952784/c-sharp-make-line-height-adjust-to-ellipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!