技术资讯

C#5秒钟后form1窗体关闭并打开form2窗体的time控件如何使用

TIME:2018-04-21

我的代码:
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private System.Windows.Forms.Timer timer1;
private DateTime startDateTime;
public Form1()
{
InitializeComponent();
startDateTime = DateTime.Now;
// 
// timer1
// 
this.timer1 = new Timer();
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
this.timer1.Start();
}

private void timer1_Tick(object sender, EventArgs e)
{
DateTime dt = DateTime.Now;
TimeSpan ts = dt.Subtract(startDateTime);
if (ts.Seconds == 3)
{
Form2 f2 = new Form2();
f2.Show();
this.Hide();
}
}
}
}

上一篇

外媒:中国餐厅正在上演数字革命

下一篇

高并发MySQL占用cpu问题解决方法分享