在延迟之后,尝试在表单加载时显示Label1。然后在Label1显示之后,在进一步延迟之后尝试使Label2显示。无论是睡觉还是延迟都不会起作用。
这是我的代码:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
System.Threading.Thread.Sleep(5000)
Label1.Show()
Delay(2)
Label2.Show()
End Sub
答案 0 :(得分:1)
您最好的选择是在表单加载时将标签初始化为隐藏,然后当表单 SHOWN 时,您将运行代码......
编辑:我意识到OP想要连续展示标签,而不是在延迟后立即展示...... public int i = 1; // public variable as a counter
private void Form1_Load(object sender, EventArgs e)
{
label1.Visible = false; // start the labels as not visible.
label2.Visible = false;
}
private void Form1_Shown(object sender, EventArgs e)
{
timer1.Start(); // start up the timer.
}
private void timer1_Tick(object sender, EventArgs e)
{
// initialize a timer that iterates through the labels provided
// and set them to visible.
while(i <= 2)
{
Label test = (Label)this.Controls["label" + i.ToString()];
test.Visible = true;
i++;
break;
}
}
答案 1 :(得分:0)
这最终起作用了:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Button1.Visible = False
Button2.Visible = False
End Sub
Private Sub Form1_Show(sender As Object, e As EventArgs) Handles MyBase.Shown
Delay(5)
Button1.Visible = True
Delay(5)
Button2.Visible = True
End Sub
结束班