2016-04-26 158 views
1

我想要一个子窗体在主窗体上显示,并且有一些不透明度的所有空白空间。我使用C# winforms pop up with background faded中提供的解决方案达到了同样的效果。C#子窗体在主窗体上产生灰色效果

现在我希望在子窗体中使用的面板具有圆角。任何帮助?

我用下面的面板链接有圆角。该面板具有圆角,但矩形线(图像中突出显示)仍然可见。有没有办法让它消失? http://www.openwinforms.com/creating_cool_gradient_panel_gdi.html

enter image description here

+0

现在很棘手。在winforms中创建圆角控件并不难,但将它们与半透明窗体结合起来很困难。 我可能已经解决了这个错误的方法,但是当我开始写这么多的代码时,我无法改变它。 正确的方法可能是从[Hans Passant](http://stackoverflow.com/users/17034/hans-passant)的[这个答案](http://stackoverflow.com/a/10267279/3094533)创建半透明背景,然后找出一种方法来阻止透明度键显示在角落附近。 –

+0

我目前没有时间写出正确的答案,但也许别人可能会提供帮助。汉斯当你需要他的时候在哪里? –

+0

等待您的回复.... – Rocky

回答

1

我找到了解决办法。

在形式漆中添加:

this.BackColor = Color.Lime; 
     this.TransparencyKey = Color.Lime; 

     var hb = new HatchBrush(HatchStyle.Percent60, this.TransparencyKey); 
     e.Graphics.FillRectangle(hb, this.DisplayRectangle); 

在形式负载使面板边缘轮,其中CTRL =面板。

Rectangle bounds = new Rectangle(0, 0, ctrl.Width, ctrl.Height); 
     int iCornerRadius = 20; 
     GraphicsPath gpath = new GraphicsPath(); 
     gpath.AddArc(bounds.X, bounds.Y, iCornerRadius, iCornerRadius, 180, 90); 
     gpath.AddArc(bounds.X + bounds.Width - iCornerRadius, bounds.Y, iCornerRadius, iCornerRadius, 270, 90); 
     gpath.AddArc(bounds.X + bounds.Width - iCornerRadius, bounds.Y + bounds.Height - iCornerRadius, iCornerRadius, iCornerRadius, 0, 90); 
     gpath.AddArc(bounds.X, bounds.Y + bounds.Height - iCornerRadius, iCornerRadius, iCornerRadius, 90, 90); 
     gpath.CloseAllFigures(); 

     ctrl.Region = new Region(gpath); 
     ctrl.Show(); 
+0

即使我没有时间发布我的解决方案,我也很高兴看到它解决问题。 –