[C#] Timer + Graphics To Get Simple Animation (簡單的源碼例子,適合初學者)

來源:互聯網
上載者:User

標籤: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 (簡單的源碼例子,適合初學者)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.