2016-04-26 49 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

即使我沒有時間發佈我的解決方案,我也很高興看到它解決問題。 –