在Form1关闭后显示Form2 7秒延迟

时间:2014-08-04 11:41:34

标签: vb.net winforms

我的应用程序中有两个表单,单击form1中的按钮会显示form2。但我需要在form1&close和form2&#39>之间延迟7秒,因为我写了以下代码:

   Public Class Form1
      Dim i As Integer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      i = 0
      Me.Close()
      Timer1.Enabled = True
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
      i += 1
      If i = 7 Then
      Form1.Show()
      End If
    End Sub
  End Class

但它没有给我结果。 form2完全没有显示。我在代码中犯了什么错误?有谁可以帮助我?

提前致谢。

2 个答案:

答案 0 :(得分:0)

如果Windows窗体应用程序中没有活动表单,则应用程序将退出。因此,您可能希望隐藏主窗体而不是关闭它:

Me.Hide()

答案 1 :(得分:0)

我认为不需要不必要的时间延迟声明,因为您只需将其设置在timer control本身上

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Timer1.Interval = 7000
    Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Form2.Show()
    Me.Close()
End Sub
End Class

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Timer1.Interval = 7000
    Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Me.Close()
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    Form2.Show()
End Sub