从圆弧c#中隐藏部分线

Hide part of line from an arc c#

我试图在一条直线上画一条弧线,并让它隐藏部分直线,使该直线看起来是连续的,如下所示:

http://i188.photobucket.com/albums/z265/fac7orx/hide%20portion%20of%20line1_zpsegcc6vhy.png

到目前为止,我正在绘制图形,然后是直线,然后是圆弧。

onPaintGraphics.DrawLine(greenPen, (float)point1.X, 320f, point2.X, 0f); //portion of code drawing the line

graphGraphics.DrawArc(greenPen, 50, 50, 159f, 159f, 90, -180); //portion of code drawing the arc

尝试用纯色填充圆弧是我唯一的选择吗?我应该从弧开始的地方打断这条线,然后在弧结束的地方继续完成这条线吗?您认为我必须隐藏该行的那部分还有哪些其他选择?谢谢。

编辑:

修改代码感谢adv12解决方案:

public void DrawArcOnLine(PaintEventArgs e)
{
    float arcPosX, arcPosY, arcWidth, archHeight, startAngleArc, arcSweepAngle;

    Graphics graphGraphics = e.Graphics;

    GraphicsPath clipPath = new GraphicsPath();

    Pen greenPen = new Pen(Brushes.MediumSeaGreen);

    arcPosX = 50f;
    arcPosY = 110f;
    arcWidth = 90f;
    archHeight = 90f;
    startAngleArc = 90;
    arcSweepAngle = -180;

    graphGraphics.DrawArc(greenPen, arcPosX, arcPosY, arcWidth, archHeight, startAngleArc, arcSweepAngle);

    clipPath.AddArc(arcPosX, arcPosY, arcWidth, archHeight, startAngleArc, arcSweepAngle);

    graphGraphics.SetClip(clipPath, CombineMode.Exclude);
}

你应该画两条线。一个用于顶部,另一个用于底部。这应该适用于所有情况。

请记住,当您告诉图形系统画一条线时,您是在说 "I want a solid black line between these two points" 在您的情况下您不想要它,所以请分割该区域,直到您可以指定与之相匹配的东西。

这可以使用与 基本相同的代码来实现,但 CombineMode.Exclude:

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

graphics.SetClip(clipPath, CombineMode.Exclude);

// draw your line

graphics.ResetClip(); // remove clip

您可以按照@Guvante 的建议简单地绘制两条较短的线,但这解决了更普遍的问题,以防您的椭圆不在线上居中或者您需要使用不同的形状进行遮罩。