如何在几秒钟内显示标签并在表单中显示另一个标签

时间:2014-10-01 16:13:28

标签: c# visual-studio-2010 visual-studio label

我有一个迷你form3 https://imageshack.com/i/p1zxB6Lqp,显示运行4秒的gif图像。所以我需要展示4种不同的 相同位置的标签..

例如

label 1 - `Connecting to smtp server..`
label 2 - `Fetching recipients..`
label 3 - `Attaching necessary G-code files..`
label 4 - `Please wait sending..`

如何在相同的位置一个接一个地显示所有这些标签..所以它看起来更专业 发送邮件。

我的代码段: -

Form1中

private void button2_Click(object sender, EventArgs e)
{
    //mail inforamtion
    _f3.ShowDialog(); // - - >> is the form i wanted with all labels
    smtp.Send(msg);
    MessageBox.Show("Email Successfully Sent!!!", "Mail!!!.");
    Environment.Exit(0);

}

Form3:

    Timer formCloser = new Timer();
    private void Form3_Load(object sender, EventArgs e)
    {
        timer1.Interval = 5000;
        timer1.Enabled = true;
        timer1.Tick += new EventHandler(timer1_Tick);
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        this.DialogResult = DialogResult.OK;
        timer1.Stop();
    }

请帮帮我..如何在表格中添加标签..

1 个答案:

答案 0 :(得分:0)

找到答案..我为每个功能保留了两个计时器,

timer1只运行迷你表单5秒钟。 和计时器2只运行1秒。 如果有任何机构有更好的代码可以分享请... 最受欢迎!!

这是我的代码:

     private void Form3_Load(object sender, EventArgs e)
    {
        timer1.Interval = 5000;
        timer1.Enabled = true;
        timer1.Tick += new EventHandler(timer1_Tick);

        timer2.Interval = 1000;
        timer2.Start();
    }


    private void timer1_Tick(object sender, EventArgs e)
    {
        this.DialogResult = DialogResult.OK;
        timer1.Stop();
    }

    int StopTime = 0;
    private void timer2_Tick(object sender, EventArgs e)
    {
        StopTime++;
        if (StopTime == 1)
        {
            label1.Text = "  Connecting to smtp server..";
        }
        if (StopTime == 2)
        {
            label1.Text = "     Fetching recipients..";
        }
        if (StopTime == 3)
        {
            label1.Text = "  Attaching G-code files..";
        }
        if (StopTime == 4)
        {
            label1.Text = "                Done!!";
            StopTime = 0;
            timer2.Stop();
        }
    }