I'm following up on the need for deprecating CS.DB and Control.DoubleBuffered's getter and will post here.
總之保險起見,還是判一下版本號,下面是判斷程式碼
Version v = System.Environment.Version;
if (v.Major < 2)
{
this.SetStyle(ControlStyles.DoubleBuffer, true);
}
else
{
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
}
2、重新整理區域
原程式碼中重新整理區域是這樣設定的
private void Tick(object sender, EventArgs e)
{
// update rectangle to include where to paint for new position
// lastKnownRect.X -= 10;
// lastKnownRect.Width += 20;
lastKnownRect.Inflate(10, 5);
// create region based on updated rectangle
Region updateRegion = new Region(lastKnownRect);
// repaint the control
Invalidate(updateRegion);
Update();
}
lastKnownRect 是文字的整個區域,如果文字較長,這個重新整理區域就會比較大,但實際上我們只需要重新整理控制項顯示範圍內的區域就可以了。
所以這裡改動如下:
// Controls the animation of the text.
private void Tick(object sender, EventArgs e)
{
// update rectangle to include where to paint for new position
// lastKnownRect.X -= 10;
// lastKnownRect.Width += 20;
lastKnownRect.Inflate(10, 5);
// get the display rectangle
RectangleF refreshRect = lastKnownRect;
refreshRect.X = Math.Max(0, lastKnownRect.X);
refreshRect.Width = Math.Min(lastKnownRect.Width + lastKnownRect.X, this.Width);
refreshRect.Width = Math.Min(this.Width - lastKnownRect.X, refreshRect.Width);
// create region based on updated rectangle
// Region updateRegion = new Region(lastKnownRect);
Region updateRegion = new Region(refreshRect);
// repaint the control
Invalidate(updateRegion);
Update();
}