手頭正在做一個通訊網關,選用了C#的WINFORM作界面 用了一個ListView來實時的顯示數據傳輸情況,于是問題就來了,當數據量比較大,而且處理速度很快時,這該死的界面閃得人眼花… 廢話不多說,直接上代碼:
首先,自定義一個類ListViewNF,繼承自 System.Windows.Forms.ListView (NF=Never/No Flickering)
class ListViewNF : System.Windows.Forms.ListView { public ListViewNF() { // 開啟雙緩沖 this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true); // Enable the OnNotifyMessage event so we get a chance to filter out // Windows messages before they get to the form's WndPRoc this.SetStyle(ControlStyles.EnableNotifyMessage, true); } protected override void OnNotifyMessage(Message m) { //Filter out the WM_ERASEBKGND message if (m.Msg != 0x14) { base.OnNotifyMessage(m); } } }然后,修改我們的Form代碼中定義ListView的位置,將原來的 System.Windows.Forms.ListView listView1; 修改為 ListViewNF listView1;
//private System.Windows.Forms.ListView listView; private ListViewNF listView;一下是從其它網頁收集的個人心得: 為什么要寫自定義控件呢: protected void SetStyle( ControlStyles flag, bool value )
比如如果你要用到textbox的SetStyle,你需要創建一個自定義控件,繼承自textbox,然后就可以調用了
保護成員是不能在對象外部(相對于textbox, form的代碼是外部)直接訪問的。
|
新聞熱點
疑難解答