Reputation: 2012
I am making a windows form application and mainly my screen is divided between 3 parts like
===========================================================================
Top panel (it doesn't flicker)
===========================================================================
|| || 'it has a panel & panel contains a table layout,this tabble layout'
|| || 'has a picture box and a label, picture & text of label is'
|| ||'changed on the click of side bar menu' (PROB: this flickers a lot)
||side bar ||==============================================================
||(doesn't ||'this part also has a panel and panel contains different table'
||flicker) ||'layouts and on the click of a menu, related table layout is shown and'
|| ||'some of the parts of table layout are created dynamically.'
|| ||
|| || (PROB: this flickers a lot)
|| ||
i searched a lot and found this solution everywhere and i tried this
public constructor()
{
InitializeComponent();
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.DoubleBuffered = true;
DoubleBuffered = true;
SetStyle(ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.ResizeRedraw |
ControlStyles.ContainerControl |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.SupportsTransparentBackColor
, true);
}
i also tried this
protected override CreateParams CreateParams
{
get
{
CreateParams handleParam = base.CreateParams;
handleParam.ExStyle |= 0x02000000; // WS_EX_COMPOSITED
return handleParam;
}
}
it changes the whole background of my screen to black color.
but still problem remains the same, can someone tell me how to solve this problem and where i am doing mistake ? Thanks a lot in advance.
Upvotes: 4
Views: 1140
Reputation: 365
Without more to go on, my gut says that you are either adding a lot of data do those areas or there is a lot of resizing going on.
try this anywhere you update the screen ( adding rows to listviews/boxes/etc ) or resize the screen, or anything else that will cause the screen to redraw. ex:
public void something_resize(object sender, EventArgs e)
{
try
{
this.SuspendLayout();
// Do your update, add data, redraw, w/e.
// Also add to ListViews and Boxes etc in Batches if you can, not item by item.
}
catch
{
}
finally
{
this.ResumeLayout();
}
}
Its important to put the ResumeLayout() call in the finally block, because if an exception occurs for w/e reason, you want your window to layout, regardless of what you do with the exception.
Upvotes: 2