我希望我的板是真正透明的,所以我也跟着這篇文章上的說明: http://www.bobpowell.net/transcontrols.htm透明面板不會呈現滾動條正確
不過,我迫使我的面板始終顯示垂直滾動條。它最初不會被渲染,除非我將鼠標光標懸停在它上面,然後開始出現。除了將VerticalScroll.Visible設置爲true以外,還可以在上面的文章中添加更多內容以確保我的面板的滾動條始終可見?
這是我到目前爲止對我的自定義面板類。這是在Visual Studio 2010中使用C#.NET 4.0:
public class SkinnedList : Panel
{
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020; // WS_EX_TRANSPARENT
return cp;
}
}
public SkinnedList()
{
AdjustFormScrollbars(true);
}
public new void AdjustFormScrollbars(bool visible)
{
VerticalScroll.Visible = true;
HorizontalScroll.Visible = false;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
protected override void OnPaintBackground(PaintEventArgs e)
{
// Do not render background
}
protected void InvalidateEx()
{
if(Parent != null)
{
Rectangle rc = new Rectangle(Location, Size);
Parent.Invalidate(rc, true);
}
}
}