C# 用Timer组件开发你的动感程序!!!

前面有朋友介绍了Timer组件的应用,发现有一些不详细的地方。为此特意上传了这段代码,希望能给各位一点启发!
  其详细的介绍可阅前面一位朋友提供的文章,在此不再重复。
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

 

namespace WindowSAP
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
public int x1=0,y1=0;
private System.Timers.Timer timer1;
private System.Windows.Forms.PictureBox pictureBox1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null) 
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.timer1 = new System.Timers.Timer();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
this.SuspendLayout();
// 
// timer1
// 
this.timer1.Enabled = true;
this.timer1.SynchronizingObject = this;
this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
// 
// pictureBox1
// 
this.pictureBox1.BackgroundImage = ((System.Drawing.Bitmap)(resources.GetObject("pictureBox1.BackgroundImage")));
this.pictureBox1.Image = ((System.Drawing.Bitmap)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(144, 128);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
// 
// Form1
// 
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(142, 123);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
  this.pictureBox1});
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "Form1";
this.TopMost = true;
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() 
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
this.timer1.Enabled =true;
this.timer1.Interval =100;


}

private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
  x1+=1;
  y1+=1;
if (x1+10>=700)
x1=0;
if(y1+10>=500)
y1=0;
Point newxy=new Point ( x1,y1 );
this.DesktopLocation =newxy;

  

}

private void label1_Click(object sender, System.EventArgs e)
{

}
}
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值