[英]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°。
您可以将其添加到GraphicsPath或使用Graphics对象进行绘制 。
这是MSDN的报价:
如果图中有先前的线或曲线,则添加一条线以将先前线段的端点连接到弧的起点。
圆弧沿着由指定矩形界定的椭圆的周长追踪。 圆弧的起点是通过从椭圆的x轴(在0度角处)顺时针测量起始角度的度数来确定的。 通过从起点顺时针测量扫角的度数,可以类似地定位端点。 如果扫掠角大于360度或小于-360度,则弧分别被精确扫掠360度或-360度。
我为演示添加了弧的边界矩形。 该代码不包括它。
对于其他拐角处的圆形切口,您需要更改和扩展点阵列并添加更多/其他弧线。
其他角弧采用以下矩形:
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°
。
尺寸和扫角保持不变。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.