我正在嘗試創建矩形的簡單動畫。動畫非常簡單,矩形的起始大小爲1 x 400像素,並且使用定時器,我每25毫秒將寬度增加4px。但動畫片閃爍我設置窗體雙緩衝,但它根本沒有幫助。它似乎我必須將此屬性設置爲矩形本身,但在矩形類中沒有雙緩衝屬性:(。是否有解決方法?或者完全不同的方法也許可以執行此簡單動畫?提前致謝C# - 矩形動畫閃爍
表單代碼:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
animation_timer.Start();
}
private void animation_timer_Tick(object sender, EventArgs e)
{
rect.Width+=4;
if (rect.Width > 778)
{
animation_timer.Stop();
}
}
}
設計師代碼:
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.shapeContainer1 = new Microsoft.VisualBasic.PowerPacks.ShapeContainer();
this.rect = new Microsoft.VisualBasic.PowerPacks.RectangleShape();
this.animation_timer = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// shapeContainer1
//
this.shapeContainer1.Location = new System.Drawing.Point(0, 0);
this.shapeContainer1.Margin = new System.Windows.Forms.Padding(0);
this.shapeContainer1.Name = "shapeContainer1";
this.shapeContainer1.Shapes.AddRange(new
Microsoft.VisualBasic.PowerPacks.Shape[] {
this.rect});
this.shapeContainer1.Size = new System.Drawing.Size(784, 562);
this.shapeContainer1.TabIndex = 0;
this.shapeContainer1.TabStop = false;
//
// rect
//
this.rect.FillColor = System.Drawing.Color.Black;
this.rect.FillStyle = Microsoft.VisualBasic.PowerPacks.FillStyle.Solid;
this.rect.Location = new System.Drawing.Point(5, 66);
this.rect.Name = "rect";
this.rect.Size = new System.Drawing.Size(1, 400);
//
// animation_timer
//
this.animation_timer.Interval = 25;
this.animation_timer.Tick += new
System.EventHandler(this.animation_timer_Tick);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(784, 562);
this.Controls.Add(this.shapeContainer1);
this.DoubleBuffered = true;
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
也許這會幫助嗎? http://stackoverflow.com/questions/64272/how-to-eliminate-flicker-in-windows-forms-custom-control-when-滾動 – wiero
我不知道你的項目的要求是什麼。也許你可以主持一個WPF用戶控件。 –