要使控件「透明」,您應該將其父項的右側區域繪製到控件上。這是Button
在繪製其內容之前所做的,因此圓角將是透明的。
要模仿半透明度,你可以畫的形式到面板上,然後畫一些與阿爾法:
private void panel1_Paint(object sender, PaintEventArgs e)
{
PaintTransparentBackground(panel1, e);
using (Brush b = new SolidBrush(Color.FromArgb(128, panel1.BackColor)))
{
e.Graphics.FillRectangle(b, e.ClipRectangle);
}
}
private static void PaintTransparentBackground(Control c, PaintEventArgs e)
{
if (c.Parent == null || !Application.RenderWithVisualStyles)
return;
ButtonRenderer.DrawParentBackground(e.Graphics, c.ClientRectangle, c);
}
![Semi-transparent panel](https://i.stack.imgur.com/51a8c.png)
請注意ButtonRenderer.DrawParentBackground
不畫的控制的形式,它與面板重疊,但只有形式的背景。
的[我如何可以設置的WinForms面板的透明度或透明度?(HTTP可能重複: //stackoverflow.com/questions/4463363/how-can-i-set-the-opacity-or-transparency-of-a-panel-in-winforms) –
我已經看到了這個,但這不適合我,這就是爲什麼我問。 Thx –
我不認爲這是重複的。海報知道沒有不透明的控件。 – taffer