一段时间后更改PictureBox可见性VB.Net

时间:2018-05-02 01:38:33

标签: vb.net winforms

我目前在装载时可以看到picturebox1可见,我想将它更改为picturebox2可见,而picturebox1不会在3秒后。我一直无法明白工作。有什么建议?我环顾四周,看到了Picturebox.refresh& picturebox.update但无法让这些工作。我对如何以不同方式做到这一点的建议持开放态度。谢谢你的帮助!

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    PictureBox1.BackgroundImage = My.Resources.Resources._024689
    PictureBox2.BackgroundImage = My.Resources.Resources._152522206296244269
    PictureBox1.Visible = True
    PictureBox2.Visible = False

    InitializeComponent()

    'starts timer
    StartTimer.Interval = 1000
    StartTimer.Start()

End Sub

Private Sub StartTimer_Tick(sender As Object, e As EventArgs) Handles StartTimer.Tick

    time += 1
    Debug.Print("Time = " & time)

    If time = 3 Then
        PictureBox2.Visible = True
        PictureBox1.Visible = False
        StartTimer.Stop()
    End If

End Sub

1 个答案:

答案 0 :(得分:0)

为了记录,这完全符合预期:

'Ensure that resources are loaded once only.
Private ReadOnly firstImage As Image = My.Resources.Capture__56x81_
Private ReadOnly secondImage As Image = My.Resources.Capture__70x264_

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    PictureBox1.Image = firstImage
    Timer1.Start()
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Timer1.Stop()
    PictureBox1.Image = secondImage
End Sub

请注意,设计师将Interval的{​​{1}}设置为3000。