如何显示标签几秒钟,并在表单中显示另一个标签
本文关键字:标签 显示 表单 另一个 何显示 几秒 | 更新日期: 2023-09-27 18:25:18
我有一个迷你表单3https://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();
}
请帮帮我。。如何在表单中添加标签.
找到了答案。。我为每个功能保留了两个计时器,
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();
}
}