2013-05-08 117 views
4

我想提出一個Windows窗體應用程序,主要在我的屏幕是3個部分之間劃分像如何避免屏幕閃爍?

=========================================================================== 
        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) 
||   || 

我搜索了很多,發現這個解決方案無處不在,我想這

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); 
    } 

我也試過這種

protected override CreateParams CreateParams 
{ 
get 
{ 
CreateParams handleParam = base.CreateParams; 
handleParam.ExStyle |= 0x02000000; // WS_EX_COMPOSITED  
return handleParam; 
} 
} 

它改變我的屏幕的整個背景爲黑色。

但仍然問題仍然是一樣的,有人能告訴我如何解決這個問題,我在哪裏做錯了? 非常感謝。

+8

屏幕不閃爍沒有更新。所以請向我們展示重複更新閃爍部分的代碼。 – 2013-05-08 13:13:28

+2

什麼控件類型是閃爍的?你在做什麼這些問題控制? EG:加載100,000條記錄以供顯示等等...... – Justin 2013-05-08 13:13:44

+1

你對這個表格做什麼?我的意思是:在哪個動作閃爍?如果你製作了一個WinForm,比如面板等3個區域,並在這些面板上放置了一些控件,它就不應該閃爍。無論是點擊面板還是拖動窗口。 – Michael 2013-05-08 13:13:58

回答

2

沒有更多的事情要做,我的直覺告訴你要麼在這些區域添加大量數據,要麼進行大量調整。

在任何更新屏幕(向列表視圖/框/等添加行)或調整屏幕大小或導致屏幕重繪的任何其他位置嘗試此操作。 例如:

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(); 
    } 
} 

其重要的放在ResumeLayout()調用的finally塊,因爲如果發生了瓦特/電子理由例外,你希望你的窗口布局,不管你用異常怎麼辦。

+0

我試過這個,但它不工作..你能告訴我這是什麼原因嗎? – Mogli 2013-05-09 05:16:53

+0

是的,最終它的工作。我不知道爲什麼它以前不工作。 – Mogli 2013-06-06 04:48:32