I have a multiple TableLayoutPanels
on MDI forms. Each table layout has multiple controls (including ObjectListView) and only the top-most is set to visible.
I implemented the solution as given in this SO answer and it works great when opening a form for the first time, because there is no flickering on the layout's child controls whilst resizing.
I also added:
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
foreach (CoTableLayoutPanel tlp in this.Controls)
{
if (tlp != null)
{
tlp.BeginUpdate();
tlp.Size = firstLayout.Size;
tlp.EndUpdate();
}
}
}
I do the above so that when I switch layouts within the form they are already all the correct size and I avoid further flickering whilst resizing. This also works fine.
However, when I have an ObjectListView
control on this derived table layout, and I switch between forms, the control is partially drawn (especially the border), a black background is shown quickly and also the last column is resized everytime (column's FillsFreeSpace
property).
If I use the standard TableLayoutPanel
, the list control behaves as expected, ie. no artifacts, no black background shown, no column resizing. However, I get the flickering back when I open the form.
The ObjectListView
has properties such as Invalidate
and Refresh
, and I've tried to call these on the form's OnGotFocus
method. The problem still persists.
Is this a problem of the ObjectListView
or can I fix the problem from within the derived table layout?
EDIT
The problem is caused by this method:
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= WS_EX_COMPOSITED;
return cp;
}
}
Commenting out this method will make the ObjectListView
work as expected but the flickering returns.
Any workaround to the above method?