我有一个大面板,里面有很多子面板。这些子面板内部是两个带有透明背景的文本字段。它基本上是从头开始构建的ListBox。背景颜色变化闪烁
我想要做的是循环每个这些子面板,并将其背景颜色更改为选定的颜色,当用户单击一个。
但是,当我点击一个新的子面板时,旧的背景颜色和新的背景颜色之间会有一个非常明显的闪烁。
注:浅蓝色是一个突出显示颜色,当用户悬停在面板。
我已经尝试设置DoubleBuffered为true为主面板和窗体本身没有太多的运气。我也尝试将ControlStyles.AllPaintingInWmPaint,ControlStyles.UserPaint和ControlStyles.OptimizedDoubleBuffer设置为true。
public class List : Panel
{
private Panel[] items;
private Label[] header; // Children of items
private Label[] footer; // Children of items
public List()
{
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
AutoScroll = true;
BackColor = Color.White;
//DoubleBuffered = true;
HorizontalScroll.Visible = false;
HorizontalScroll.Enabled = false;
VerticalScroll.Visible = true;
VerticalScroll.Enabled = true;
}
public void renderItemsSelected(Color color)
{
for (int q = 0; q < itemsSelected.Count; q++)
{
int i = getPos();
items[i].BackColor = color;
}
}
}
所以我想知道如果有人有任何想法?
为'items'数组中的每个项目启用双缓冲。谢谢。 – Khronos 2012-02-23 06:20:02