Winform下無閃爍走馬燈效果實現

來源:互聯網
上載者:User

最近需要在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

.DB
none APWMP, UserPaint Yes We are considering NOT deprecating this flag because ODB isn't an exact replacement for DB.
ControlStyle

.ODB
none none No Works, but without APWMP set you'll buffer foreground and background separately and will still see flicker.
Control

.DoubleBuffered
sets CS.ODB, CS.APWMP none No Works for most mainstream buffering needs. Getter is peculiar in that it only checks CS.ODB.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.