在C#中单击按钮时出现多个面板

时间:2014-01-09 12:45:42

标签: c# winforms

我已经创建了一个计时器,现在我希望每当我点击“添加计时器”按钮时,现有面板下面的表格上会出现一个具有相同现有面板属性的新面板。我怎么能这样做?

到目前为止我的代码:

public partial class Form1 : Form
{
    int countdown;
    public Form1()
    {
        InitializeComponent();
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        countdown = int.Parse(textBox1.Text);
        TimeSpan ts = TimeSpan.FromSeconds(countdown);
        label4.Text = string.Format("{0:D2}:{1:D2}:{2:D2}", ts.Hours, ts.Minutes, ts.Seconds);
        ts = ts.Subtract(new TimeSpan(0, 0, 1));

        textBox1.Text = ts.TotalSeconds.ToString();
        label4.Text = string.Format("{0:D2}:{1:D2}:{2:D2}", ts.Hours, ts.Minutes, ts.Seconds);
        if (ts.TotalSeconds == 0)
        {
            //timer1.Stop();
            label4.ForeColor = System.Drawing.Color.Red;
            MessageBox.Show("Times Up!");
        }
    }

    private void button3_Click(object sender, EventArgs e)
    {
        if(button3.Text=="Start")
        {
            timer1.Enabled = true;
            button3.Text = "Reset";
            timer1.Start();
        }
        else
        {
            timer1.Enabled = false;
            button3.Text = "Start";
            timer1.Stop();
            textBox1.Text = "00";
            label4.Text = "00:00:00";
        }
    }

    private void button4_Click(object sender, EventArgs e)
    {
        if(button4.Text=="Pause")
        {
            timer1.Stop();
            button4.Text = "Resume";
        }
        else
        {
            button4.Text = "Pause";
            timer1.Start();
        }

    }

0 个答案:

没有答案