標籤:des style blog color io os ar java for
>_<" 這是一個非常簡單的利用C#的視窗工程創立的程式,用來做一個簡單的動畫,涉及Timer和Graphics,適合初學者,高手略過~
PS:請忽略功能表列的東西~背景改成了白色!
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms;10 using System.Drawing.Drawing2D;11 using System.Drawing.Imaging;12 13 namespace DrawHS14 {15 public partial class DrawHS : Form16 {17 public int x = 0, y = 0;//物體座標18 19 public DrawHS()20 {21 InitializeComponent();22 }23 24 private void timer1_Tick(object sender, EventArgs e)25 {26 x++; y += 10;//運動27 Refresh();//重新整理視窗,重新整理之後調用Paint函數28 }29 30 private void DrawHS_Paint(object sender, PaintEventArgs e)31 {32 Graphics g = e.Graphics;//繪圖33 Rectangle rect = new Rectangle(x, y, 100, 100);34 LinearGradientBrush lBrush = new LinearGradientBrush(rect,35 Color.Red, Color.Yellow, LinearGradientMode.BackwardDiagonal);36 g.FillRectangle(lBrush, rect); 37 }38 }39 }
[C#] Timer + Graphics To Get Simple Animation (簡單的源碼例子,適合初學者)