日期:2014-05-18 浏览次数:20931 次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Dynamic
{
public partial class Dynamic : Form
{
public Dynamic()
{
InitializeComponent();
}
int offset = 25;//垂直增量
int offset1 = 25;//水平增量
private void Dynamic_FormClosing(object sender, FormClosingEventArgs e)
{
timer_dynamic.Enabled = true;
e.Cancel = true;
}
private void timer_dynamic_Tick(object sender, EventArgs e)
{
this.Top += offset;
this.Height -= 70;
if (this.Top > 300)
{
offset = 0;
this.Left += offset1;
this.Width = -50;
if (this.Left > 600)
{
offset1 = 0;
}
}
}
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int offset = 25;//垂直增量
int offset1 = 25;//水平增量
int tempHeight;
int tempWidth;
private void timer1_Tick(object sender, EventArgs e)
{
tempHeight=this.Height;
tempWidth=this.Width;
this.Top += offset;
this.Height -= 70;
if (this.Top > 300)
{
offset = 0;
this.Left += offset1;
this.Width -=50;
if (this.Left > 600)
{
offset1 = 0;
}
}
if(this.Width==tempWidth&&this.Height==tempHeight)
{
this.Close();
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
timer1.Enabled = !timer1.Enabled;
if (timer1.Enabled)
{
e.Cancel = true;
}
}
}
------解决方案--------------------
你在关闭事件中调用你写的要显示效果的方法不就行了嘛
private void Dynamic_FormClosing(object sender, FormClosingEventArgs e)
{
timer_dynamic.Enabled = true;
timer_dynamic_Tick(null, null);
}