回复 楼主 luohongtai
我还是把它的源码给你贴出来吧!
private void InitializeComponent()
{
= new Container();
this.label1 = new Label();
this.groupBox1 = new GroupBox();
this.button4 = new Button();
this.button3 = new Button();
this.button2 = new Button();
this.button1 = new Button();
this.timer1 = new Timer();
this.timer2 = new Timer();
this.timer3 = new Timer();
this.groupBox1.SuspendLayout();
base.SuspendLayout();
this.label1.BorderStyle = BorderStyle.Fixed3D;
this.label1.Font = new Font("宋体", 18f, FontStyle.Bold, GraphicsUnit.Point, 134);
this.label1.Location = new Point(36, 7);
this.label1.Name = "label1";
this.label1.Size = new Size(162, 31);
this.label1.TabIndex = 0;
this.label1.Text = "飘动动画窗体";
this.groupBox1.BackColor = SystemColors.Control;
this.groupBox1.Controls.Add(this.button4);
this.groupBox1.Controls.Add(this.button3);
this.groupBox1.Controls.Add(this.button2);
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Location = new Point(17, 41);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new Size(200, 108);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "飘动动画窗体的控制";
this.button4.Location = new Point(112, 63);
this.button4.Name = "button4";
this.button4.Size = new Size(69, 37);
this.button4.TabIndex = 3;
this.button4.Text = "停止飘动";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new EventHandler(this.button4_Click);
this.button3.Location = new Point(34, 63);
this.button3.Name = "button3";
this.button3.Size = new Size(69, 37);
this.button3.TabIndex = 2;
this.button3.Text = "飘动窗体";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new EventHandler(this.button3_Click);
this.button2.Location = new Point(112, 20);
this.button2.Name = "button2";
this.button2.Size = new Size(69, 37);
this.button2.TabIndex = 1;
this.button2.Text = "垂直飘动";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new EventHandler(this.button2_Click);
this.button1.Location = new Point(36, 20);
this.button1.Name = "button1";
this.button1.Size = new Size(69, 37);
this.button1.TabIndex = 0;
this.button1.Text = "水平飘动";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new EventHandler(this.button1_Click);
this.timer1.Interval = 10;
this.timer1.Tick += new EventHandler(this.timer1_Tick);
this.timer2.Interval = 10;
this.timer2.Tick += new EventHandler(this.timer2_Tick);
this.timer3.Interval = 10;
this.timer3.Tick += new EventHandler(this.timer3_Tick);
base.AutoScaleDimensions = new SizeF(6f, 12f);
base.AutoScaleMode = AutoScaleMode.Font;
base.ClientSize = new Size(234, 161);
base.Controls.Add(this.groupBox1);
base.Controls.Add(this.label1);
base.Name = "Form1";
this.Text = "飘动动画窗体";
base.Load += new EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
base.ResumeLayout(false);
}
private void button1_Click(object sender, EventArgs e)
{
this.timer1.Enabled = true;
this.timer2.Enabled = false;
this.timer3.Enabled = false;
}
private void button2_Click(object sender, EventArgs e)
{
this.timer1.Enabled = false;
this.timer2.Enabled = true;
this.timer3.Enabled = false;
}
private void button3_Click(object sender, EventArgs e)
{
this.timer1.Enabled = false;
this.timer2.Enabled = false;
this.timer3.Enabled = true;
}
private void button4_Click(object sender, EventArgs e)
{
this.timer1.Enabled = false;
this.timer2.Enabled = false;
this.timer3.Enabled = false;
}
private void Form1_Load(object sender, EventArgs e)
{
this.timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
Point point = new Point(base.DesktopLocation.X, base.DesktopLocation.Y);
if ((point.X + base.Width) < this.ScreenWidth)
{
base.DesktopLocation = new Point(point.X + 1, point.Y);
}
else
{
base.DesktopLocation = new Point(0, 0);
}
}
private void timer2_Tick(object sender, EventArgs e)
{
Point point = new Point(base.DesktopLocation.X, base.DesktopLocation.Y);
if ((point.Y + base.Height) < this.ScreenHeight)
{
base.DesktopLocation = new Point(point.X, point.Y + 1);
}
else
{
base.DesktopLocation = new Point(0, 0);
}
}
private void timer3_Tick(object sender, EventArgs e)
{
Point point = new Point(base.DesktopLocation.X, base.DesktopLocation.Y);
if (((point.X + base.Width) < this.ScreenWidth) || ((point.Y + base.Height) < this.ScreenHeight))
{
base.DesktopLocation = new Point(point.X + 1, point.Y + 1);
}
else
{
base.DesktopLocation = new Point(0, 0);
}
}
public class Form1 : Form
{
// Fields
private Button button1;
private Button button2;
private Button button3;
private Button button4;
private IContainer components;
private GroupBox groupBox1;
private Label label1;
private int ScreenHeight;
private int ScreenWidth;
private Timer timer1;
private Timer timer2;
private Timer timer3;
// Methods
public Form1();
private void button1_Click(object sender, EventArgs e);
private void button2_Click(object sender, EventArgs e);
private void button3_Click(object sender, EventArgs e);
private void button4_Click(object sender, EventArgs e);
protected override void Dispose(bool disposing);
private void Form1_Load(object sender, EventArgs e);
private void InitializeComponent();
private void timer1_Tick(object sender, EventArgs e);
private void timer2_Tick(object sender, EventArgs e);
private void timer3_Tick(object sender, EventArgs e);
}
自己整理一下啊,可以做个和它一模一样的,哈哈..