C#计时器没停?

Lyn*_*rum 2 c#

这就是我所拥有的,为什么我的计时器没有停止?我不确定我做错了什么.我是C#的新手,我正试图让它成为我的启动画面隐藏(form1)和我的程序启动(samptool)然而我的程序启动但启动画面停留并且计时器重置而不是停止.每6.5秒,应用程序将在新窗口中打开.

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;
using System.Timers;
namespace SplashScreen.cs
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
            timer1.Interval = 250;
            timer2.Interval = 6500;
            timer1.Start();
            timer2.Start();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.progressBar1.Increment(5);
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            SampTool w = new SampTool();
            Form1 m = new Form1();
            timer1.Enabled = false;
            timer1.Stop();
            timer2.Enabled = false;
            timer2.Stop();
            m.Hide();
            w.Show();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Jit*_*ite 7

使用new关键字时,您将创建一个类的新实例:

Form1 m = new Form1();
Run Code Online (Sandbox Code Playgroud)

创建新实例时,将constructor调用该构造函数(构造函数是与该类名称相同的方法).
这将再次运行构造函数中的所有代码,从而创建新的计时器.

要关闭当前表单,您应该只运行表单Hide方法:

private void timer2_Tick(object sender, EventArgs e)
{
    timer1.Stop();
    timer2.Stop();
    SampTool sampTool = new SampTool();
    sampTool.Show();

    Hide();  // call the Forms Hide function.
}
Run Code Online (Sandbox Code Playgroud)