在VB.Net中更改特定时间后的PictureBox可见性
我现在已经将它设置为加载时可以看到picturebox1的位置,我想将它更改为picturebox2可以看到并且picturebox1在3秒后不可见的位置。我一直无法让它明显起作用。有什么建议吗?我环顾四周,看到了Picturebox.refresh和Picturebox.update,但未能使其正常工作。我也愿意接受关于如何以不同方式实现这一点的建议。谢谢你的帮助在VB.Net中更改特定时间后的PictureBox可见性,vb.net,winforms,Vb.net,Winforms,我现在已经将它设置为加载时可以看到picturebox1的位置,我想将它更改为picturebox2可以看到并且picturebox1在3秒后不可见的位置。我一直无法让它明显起作用。有什么建议吗?我环顾四周,看到了Picturebox.refresh和Picturebox.update,但未能使其正常工作。我也愿意接受关于如何以不同方式实现这一点的建议。谢谢你的帮助 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles
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
为了记录在案,这完全符合预期:
'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
请注意,
Timer1
的Interval
已在设计器中设置为3000。如果希望在3秒后发生某件事,为什么要将计时器的Interval
设置为1秒?你为什么不把它设为3秒?勾选
事件将被引发一次,并且只会引发一次,此时,作为第一个操作,停止计时器
,然后执行任何其他适当的操作。此外,不要干扰多个图片框及其可见性,为什么不使用一个PictureBox
并更改其Image
或BackgroundImage
属性?另外,为什么要使用BackgroundImage
而不是Image
?可能有合理的原因,但我已经看到很多情况下这样做没有一个好的理由。我最初使用的是1个图片框,我使用的是图像属性。我遇到的问题是,当我使用图像时,它们不会显示任何变化。看起来,picturebox似乎卡在了第一张图像上。如果您对发生这种情况的原因有任何建议,我将非常感谢您的输入。顺便说一下,请从加载
事件处理程序中调出初始化组件
调用。在构造函数中调用,默认情况下自动生成构造函数。也许这就是事情没有按预期进行的原因。