2016-07-29 73 views
1

我想周圍畫panel.But邊框我有如下問題: enter image description here
邊界不夾。
我的代碼:如何創建一個圓角面板和剪輯的約束

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); 
     } 
} 

回答

1

可以使面板的背景色透明,然後自己繪製背景是這樣的:

e.Graphics.FillPath(Brushes.LightBlue, path); 

您繪製邊框右側前。
然而,WinForms的透明度並不十分完美,角落只需要父控件的BackColor,所以如果你打算在它下面畫任何東西,它們仍然會覆蓋它。

+0

您的解決方案幫助了我!我需要添加一個新的Backgound屬性,並將背景顏色設置爲面板@ zockDoc內的控件的透明 – Jandy