TheNewbie
TheNewbie

Reputation: 112

Timer acting weird

Hi guys I have another problem which is all about the timer..the form that I would want to show for 3 seconds is only showing for about half a second. Please help me thanks in advance

Main form code:

Private Sub submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles submit.Click
    'question 1
    If Label1.Text = "Who invented the airplane?" And TextBox1.Text = "third" Then

        Label2.Text = (Label2.Text) + 1

        correctmsg.Show()
        correctmsg.Hide()

        Label1.Text = "Who invented the telephone?"
        Return 'Don't do any more checks this time around

    ElseIf Label1.Text = "Who invented the airplane?" Then
        'Reason ElseIf (In case the question was 'who invented the telephone' then the first errormessage should not not be shown)
        wrongmsg.Show()
        Return

    End If

Splash form code:

Public Class correctmsg

Private Sub correctmsg_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Dim mysplash As New correctmsg
    mysplash.Timer1.Interval = 3000

End Sub

End Class

Upvotes: 0

Views: 82

Answers (1)

Something like this:

Public Class correctmsg
  ' correctmsg == mysplash ??? so this is a form??


 Private Sub correctmsg_Load(ByVal sender As System.Object, 
      ByVal e As System.EventArgs) Handles MyBase.Load

      Timer1.Interval = 3000    ' could be a timer here

 End Sub

 Public Sub ShowMsg
     Timer1.Enabled = true
     me.Visible = True
 End Sub

 Private Sub Timer1_Tick(ByVal sender As System.Object, 
           ByVal e As System.EventArgs) Handles Timer1.Tick

     Timer1.Enabled = False
     Me.Visible = False

 End Sub
 End Class

I am just showing the form by making it visible. No need to make a new form. When the timer expires, hide the form and disable the timer. To use it:

    correctmsg.ShowMsg
    ' this was hiding the form as soon as it shows:
    'correctmsg.Hide()

Upvotes: 2

Related Questions