我试图在面板周围绘制边框。但我遇到的问题如下:
边框没有剪辑。
我的代码:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
int diameter = radius * 2;
Size size = new Size(diameter, diameter);
int w = size.Width-1;
int h = size.Height-1;
Rectangle arc = new Rectangle(bounds.Location.X, bounds.Location.Y, w, h);
GraphicsPath path = new GraphicsPath();
path.AddArc(arc, 180, 90);
arc.X = bounds.Right - diameter;
path.AddArc(arc, 270, 90);
arc.Y = bounds.Bottom- diameter;
path.AddArc(arc, 0, 90);
arc.X = bounds.Left;
path.AddArc(arc, 90, 90);
path.CloseFigure();
GraphicsPath GraphPath = path;
this.Region = new Region(GraphPath);
using (Pen pen = new Pen(Color.Blue, 1)) {
e.Graphics.DrawPath(pen, path);
}
}
答案 0 :(得分:1)
你可以让面板的BackColor透明,然后像这样自己画背景:
e.Graphics.FillPath(Brushes.LightBlue, path);
在你画边框之前然而,WinForms的透明度并不是非常完美,角落只会占用父控件的BackColor,所以如果你打算在它下面绘制任何东西,它们仍会覆盖它。