我试图创建一个弹出泡泡,在底部有一个圆形的矩形和一个东西,我在下面的图片上用绿色圈起来:

但正如你已经猜到的,这不是我想要的样子,而是:

我想出了如何像我应该的那样画它,但在这种情况下,当我在我的路径周围加上边框时,它将这个小三角形和圆形矩形分开。
下面是我正在使用的代码:
public static GraphicsPath CreateBubblePath(Rectangle rect, int radius)
{
GraphicsPath p = new GraphicsPath();
GraphicsPath p2 = new GraphicsPath();
p.StartFigure();
p2.StartFigure();
int pointHeigt = 3 * radius;
//Top Left Corner
p.AddArc(rect.X, rect.Y, 2 * radius, 2 * radius, 180, 90);
//Top Edge
p.AddLine(rect.X + radius, rect.Y, rect.X + rect.Width - radius, rect.Y);
//Top Right Corner
p.AddArc(rect.X + rect.Width - 2 * radius, rect.Y, 2 * radius, 2 * radius, 270, 90);
//Right Edge
p.AddLine(rect.X + rect.Width, rect.Y + radius, rect.X + rect.Width, rect.Y + rect.Height - radius - pointHeigt);
//Bottom Right Corner
p.AddArc(rect.X + rect.Width - (2 * radius), rect.Y + rect.Height - radius - pointHeigt, 2 * radius, 2 * radius, 0, 90);
//Bottom Edge 1/2
//METHOD 1
p.AddLine(rect.X + rect.Width - radius, rect.Y + rect.Height - 2 * radius, rect.X + (rect.Width / 2) + pointHeigt, rect.Y + rect.Height - 2 * radius);
p.AddArc(rect.X + (rect.Width / 2), rect.Y + rect.Height - 2 * radius , pointHeigt, pointHeigt, 180, 90);
p.AddArc(rect.X + (rect.Width / 2) - pointHeigt, rect.Y + rect.Height - 2 * radius, pointHeigt, pointHeigt, 270, 90);
p.AddLine(rect.X + (rect.Width / 2) - pointHeigt, rect.Y + rect.Height - 2 * radius, rect.X + radius, rect.Y + rect.Height - 2 * radius);
//METHOD 2///////////////////////////////////////
//p.AddLine(rect.X + rect.Width - radius, rect.Y + rect.Height - 2 * radius, rect.X + radius, rect.Y + rect.Height - 2 * radius);
//p2.AddArc(rect.X + (rect.Width / 2), rect.Y + rect.Height - 2 * radius, pointHeigt, pointHeigt, 180, 90);
//p2.AddArc(rect.X + (rect.Width / 2) - pointHeigt, rect.Y + rect.Height - 2 * radius, pointHeigt, pointHeigt, 270, 90);
//p2.CloseFigure();
////////////////////////////////
//Bottom Left Corner
p.AddArc(rect.X, rect.Y + rect.Height - radius - pointHeigt, 2 * radius, 2 * radius, 90, 90);
//Left Edge
p.AddLine(rect.X, rect.Y + rect.Height - radius - pointHeigt, rect.X, rect.Y + radius);
p.CloseFigure();
//METHOD 2
//p.AddPath(p2, true);
return p;
}发布于 2014-06-12 13:29:39
我认为弧形的角度才是问题所在。
我把它们改成了这个:
p.AddArc(rect.X + (rect.Width / 2), rect.Y + rect.Height - 2 * radius, pointHeigt, pointHeigt, 270, -90);
p.AddArc(rect.X + (rect.Width / 2) - pointHeigt, rect.Y + rect.Height - 2 * radius, pointHeigt, pointHeigt, 0, -90);矩形底部的点现在看起来是正确的。
有关弧形角度的信息可以在用于GraphicsPath.AddArc的MSDN页面上找到,特别是在备注部分:
该弧线沿着以指定矩形为界的椭圆的周长进行跟踪。弧的起始点是由椭圆的x轴顺时针方向(在0度角处)测量开始角的度数来确定的。端点也是通过从起始点顺时针方向测量扫描角中的度数来定位的。如果扫描角大于360度或小于-360度,则弧分别被扫360度或-360度。
发布于 2014-06-12 13:28:50
好的,我不知道我可以在sweepAngle中添加一个负数,所以知道我只更改了以下2行:
从…
p.AddArc(rect.X + (rect.Width / 2), rect.Y + rect.Height - 2 * radius , pointHeigt, pointHeigt, 180, 90);
p.AddArc(rect.X + (rect.Width / 2) - pointHeigt, rect.Y + rect.Height - 2 * radius, pointHeigt, pointHeigt, 270, 90);至:
p.AddArc(rect.X + (rect.Width / 2), rect.Y + rect.Height - 2 * radius , pointHeigt, pointHeigt, 270, -90);
p.AddArc(rect.X + (rect.Width / 2) - pointHeigt, rect.Y + rect.Height - 2 * radius, pointHeigt, pointHeigt, 0, -90);https://stackoverflow.com/questions/24181864
复制相似问题