/// //做一个动画 一个方块从原来的位置慢慢往下移动
/// 用timer picturebox两个控件
public partial class Form3 : Form
{
PictureBox p;
public Form3()
{
InitializeComponent();
}
private void Form3_Load(object sender, EventArgs e)
{
this.Width = 800;
this.Height = 600;
Bitmap newBitmap = new Bitmap(50, 50, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
Graphics g = Graphics.FromImage(newBitmap);
g.FillRectangle(new SolidBrush(Color.Red), new Rectangle(0, 0, 50, 50));
//newBitmap.Save(System.IO.Path.Combine (Environment.CurrentDirectoryEnvironment.CurrentDirectory,"1.png"), ImageFormat.Png);
p = new PictureBox();
p.Image = newBitmap;
this.Controls.Add(p);
p.Top = 50;
p.Left = 10;
System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
timer1.Tick += new System.EventHandler(this.timer1_Tick);
timer1.Interval = 1000; // 设置timer时间,单位是毫秒
timer1.Enabled = true; // 启动 timer
//Button
}
private void timer1_Tick(object sender, EventArgs e)
{
p.Top = p.Top + 50;
}
}
编辑器加载中...