码迷,mamicode.com
首页 > 其他好文 > 详细

[C#] Timer + Graphics To Get Simple Animation (简单的源码例子,适合初学者)

时间:2014-10-06 02:42:19      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   io   os   ar   java   for   

 

>_<" 这是一个非常简单的利用C#的窗口工程创立的程序,用来做一个简单的动画,涉及Timer和Graphics,适合初学者,高手略过~

bubuko.com,布布扣

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 DrawHS
14 {
15     public partial class DrawHS : Form
16     {
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 (简单的源码例子,适合初学者)

标签:des   style   blog   color   io   os   ar   java   for   

原文地址:http://www.cnblogs.com/zjutlitao/p/4007806.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!