绘制pictureBox c#
Drawing pictureBox c#
我正在尝试制作一个看起来像这样的自定义图片框 -
到目前为止,我所做的只是 -
使用此代码 -
protected void UpdateRegion()
{
var path = new GraphicsPath();
Point[] points =
{
new Point( 0, 0),
new Point(0, ClientSize.Height-80),
new Point(80 , ClientSize.Height),
new Point(ClientSize.Width-80, ClientSize.Height),
new Point(ClientSize.Width, ClientSize.Height-80),
new Point(ClientSize.Width , 0)
};
path.AddPolygon(points);
path.FillMode = FillMode.Winding;
this.Region = new Region(path);
}
给你:
GraphicsPath path = new GraphicsPath();
path.FillMode = FillMode.Winding;
int cut = 80;
Rectangle cr = panel1.ClientRectangle;
Point[] points =
{
new Point(0, cr.Height - cut),
new Point(0, 0),
new Point(cr.Width, 0),
new Point(cr.Width, cr.Height - cut),
new Point(cr.Width - cut, cr.Height),
new Point(cut, cr.Height),
new Point(0, cr.Height - cut),
};
path.AddPolygon(points);
Rectangle arcRect = new Rectangle(0, cr.Height - 2 * cut, 2 * cut, 2 * cut);
path.AddArc(arcRect, 90f, 90f);
弧由边界矩形定义,在我们的例子中,边界矩形的大小是切割的两倍。它从 x 轴顺时针 90° 开始,然后(至少)再旋转 90°。
您可以add it to a GraphicsPath or draw it with a Graphics反对。
引用自 MSDN:
If there are previous lines or curves in the figure, a line is added
to connect the endpoint of the previous segment to the beginning of
the arc.
The arc is traced along the perimeter of the ellipse bounded by the
specified rectangle. The starting point of the arc is determined by
measuring clockwise from the x-axis of the ellipse (at the 0-degree
angle) by the number of degrees in the start angle. The endpoint is
similarly located by measuring clockwise from the starting point by
the number of degrees in the sweep angle. If the sweep angle is
greater than 360 degrees or less than -360 degrees, the arc is swept
by exactly 360 degrees or -360 degrees, respectively.
请注意,我添加了圆弧的边界矩形仅用于演示。代码不包含它。
对于其他角的圆角切割,您需要更改和扩展点数组并添加 more/other 弧。
其他角弧采用这些矩形:
Rectangle arcRectTL = new Rectangle(0, 0, 2 * cut, 2 * cut);
Rectangle arcRectTR = new Rectangle(cr.Width - 2 * cut, 0, 2 * cut, 2 * cut);
Rectangle arcRectBR = new Rectangle(cr.Width - 2*cut, cr.Height - 2*cut, 2*cut, 2*cut);
起始角度分别为:180°, 270° and 0°
.
尺寸和后掠角保持不变。
我正在尝试制作一个看起来像这样的自定义图片框 -
到目前为止,我所做的只是 -
使用此代码 -
protected void UpdateRegion()
{
var path = new GraphicsPath();
Point[] points =
{
new Point( 0, 0),
new Point(0, ClientSize.Height-80),
new Point(80 , ClientSize.Height),
new Point(ClientSize.Width-80, ClientSize.Height),
new Point(ClientSize.Width, ClientSize.Height-80),
new Point(ClientSize.Width , 0)
};
path.AddPolygon(points);
path.FillMode = FillMode.Winding;
this.Region = new Region(path);
}
给你:
GraphicsPath path = new GraphicsPath();
path.FillMode = FillMode.Winding;
int cut = 80;
Rectangle cr = panel1.ClientRectangle;
Point[] points =
{
new Point(0, cr.Height - cut),
new Point(0, 0),
new Point(cr.Width, 0),
new Point(cr.Width, cr.Height - cut),
new Point(cr.Width - cut, cr.Height),
new Point(cut, cr.Height),
new Point(0, cr.Height - cut),
};
path.AddPolygon(points);
Rectangle arcRect = new Rectangle(0, cr.Height - 2 * cut, 2 * cut, 2 * cut);
path.AddArc(arcRect, 90f, 90f);
弧由边界矩形定义,在我们的例子中,边界矩形的大小是切割的两倍。它从 x 轴顺时针 90° 开始,然后(至少)再旋转 90°。
您可以add it to a GraphicsPath or draw it with a Graphics反对。
引用自 MSDN:
If there are previous lines or curves in the figure, a line is added to connect the endpoint of the previous segment to the beginning of the arc.
The arc is traced along the perimeter of the ellipse bounded by the specified rectangle. The starting point of the arc is determined by measuring clockwise from the x-axis of the ellipse (at the 0-degree angle) by the number of degrees in the start angle. The endpoint is similarly located by measuring clockwise from the starting point by the number of degrees in the sweep angle. If the sweep angle is greater than 360 degrees or less than -360 degrees, the arc is swept by exactly 360 degrees or -360 degrees, respectively.
请注意,我添加了圆弧的边界矩形仅用于演示。代码不包含它。
对于其他角的圆角切割,您需要更改和扩展点数组并添加 more/other 弧。
其他角弧采用这些矩形:
Rectangle arcRectTL = new Rectangle(0, 0, 2 * cut, 2 * cut);
Rectangle arcRectTR = new Rectangle(cr.Width - 2 * cut, 0, 2 * cut, 2 * cut);
Rectangle arcRectBR = new Rectangle(cr.Width - 2*cut, cr.Height - 2*cut, 2*cut, 2*cut);
起始角度分别为:180°, 270° and 0°
.
尺寸和后掠角保持不变。