最近需要在Winform項目中實現一個走馬燈的效果,一開始用了一些辦法比如移動Label控件,效果總是不太好,移動文本時總有閃爍的現象。後來找了一個國外的開源控件,應用了一下,效果還不錯。仔細閱讀了一下代碼,發現還有一些地方值得改進,現把代碼以及改動說明貼出來,和大家分享。
控件出處:http://www.codeproject.com/KB/miscctrl/ScrollingTextControlArtic.ASPx
我的改動:
1、DoubleBuffer 的設置
原代碼中用的是 this.SetStyle(ControlStyles.DoubleBuffer, true); 但一些網友反映這個標志在.net 2.0 以上版本無效。說句老實話,我也不是特別確信,MSDN上也沒有說明這一點。在我的.Net 2.0 系統中,兩種設置的效果似乎沒有太多區別。在一個國外網站上找到他們的區別,下面是原文:
ControlStyles == CS
AllPaintingInWMPaint == APWMP
OptimizedDoubleBuffer = ODB
DoubleBuffer = DB
An earlIEr permutation of the design called for ODB to simply be a combinationof DB, APWMP and UserPaint. Through several design changes, the two control styles are nearly synonymous, but they still have differences. Now that we've broken that, we may considerun-deprecating CS.DB to retain . Here is a more complete summary of the current design:
Mechanism Side effects Other flags required to work Require APWMP? Notes ControlStyle