How to avoid screen flicker?

I am making a window-shaped application, and basically my screen is divided into 3 parts, for example

=========================================================================== 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 entire background of my screen to black.

but the problem remains the same, can someone tell me how to solve this problem and where am I making a mistake? Thank you very much in advance.

+4
source share
1 answer

There is no need to continue, my gut says that you either add a lot of data to these areas, or there are a lot of resizing.

try to do this wherever you refresh the screen (add lines to the list view / box / etc) or change the size of the screen, or anything else that will redraw the screen. 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(); } } 

It is important to add a call to ResumeLayout () to the finally block, because if an exception occurs due to w / e, you want your window to be in the layout, no matter what you do with the exception.

+2
source

Source: https://habr.com/ru/post/1479742/


All Articles