0
A
回答
0
依靠Timer
可以獲得足夠好的效果。在這裏,您可以看到一個示例代碼,演示如何在單擊按鈕後爲主表單的增大尺寸設置動畫。通過增加/減少所有變量(X/Y包括數值或間隔),您可以完全控制動畫「看起來」的方式。只需在表格和下面的代碼中包含一個按鈕(button1
)和一個計時器(timer1
)。
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int timerInterval, curWidth, curHeight, incWidth, incHeight, maxWidth, maxHeight;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
curWidth = this.Location.X + this.Width;
curHeight = this.Location.Y + this.Height;
incWidth = 100;
incHeight = 20;
maxWidth = 2000;
maxHeight = 1500;
timerInterval = 100;
timer1.Enabled = false;
timer1.Interval = timerInterval;
}
private void timer1_Tick(object sender, EventArgs e)
{
curWidth = curWidth + incWidth;
curHeight = curHeight + incHeight;
if (curWidth >= maxWidth)
{
curWidth = maxWidth;
}
if (curHeight >= maxHeight)
{
curHeight = maxHeight;
}
this.Width = curWidth;
this.Height = curHeight;
if (this.Width == maxWidth && this.Height == maxHeight)
{
timer1.Stop();
}
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = !timer1.Enabled;
}
}
}
相關問題
- 1. Animate,Jump Position,Animate
- 2. 停止Jquery .Animate()新的.Animate()
- 3. Animate`positionViewAtIndex`
- 4. Animate NSWindow
- 5. Animate nsmenuitem
- 6. Animate UITextViews
- 7. JQuery Animate
- 8. Animate ImageView
- 9. animate backgroundPosition
- 10. Animate canvas.drawCircle
- 11. Animate RenderTransformOrigin
- 12. Animate CCSprite
- 13. Animate UITableViewCell
- 14. Animate UITextField
- 15. Animate CGContextFillRect
- 16. 鼠標懸停.animate停止之前.animate
- 17. jquery animate height bouncing
- 18. Animate Same Activity
- 19. jQuery animate set fallback
- 20. Waypoint Jquery Animate
- 21. Animate webview android
- 22. Animate DataContext Silverlight
- 23. De-animate Sticky Header
- 24. UISearchDisplayController animate reloadData
- 25. jQuery的.animate()
- 26. Animate NavigationBar標題
- 27. Loop and animate div
- 28. Animate content div'height'to'Auto'onclick - jQuery
- 29. 與jQuery Animate translate3d
- 30. Animate display:none to display:inline
在'button1_Click'可以更簡潔這樣的代碼'timer1.Enabled = timer1.Enabled;!' –
@KingKing好點,我已經更新了代碼。老實說,我不知道Timer可以通過Enabled屬性來觸發;我認爲這是一個表明狀態的布爾變量。 – varocarbas