drjester
drjester

Reputation: 51

continously change form with timer and proggres bar vb.net

i have 2 form
i want each form to continously change from form1 to form2 and form2 to from1
i already try

code in form 1

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If ProgressBar1.Value < 300 Then
            ProgressBar1.Value += 1
        ElseIf ProgressBar1.Value = 300 Then
            Timer1.Stop()
            Me.Close()
            Form2.Show()
        End If
    End Sub
End Class  

code in form2

Public Class Form2
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If ProgressBar1.Value < 300 Then
            ProgressBar1.Value += 1
        ElseIf ProgressBar1.Value = 300 Then
            Timer1.Stop()
            Me.Close()
            Form1.Show()
        End If
    End Sub
End Class

please help

Upvotes: 0

Views: 170

Answers (1)

WozzeC
WozzeC

Reputation: 2660

Think I found your issue. It works for me since I didn't use Form1 or Form2 as startup form. However, when you use Form1 as startup form the software closes when you close Form1.

What you have to do is this:

Change your code on both form to this: Show before Close

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    If ProgressBar1.Value < 300 Then
       ProgressBar1.Value += 1
    ElseIf ProgressBar1.Value = 300 Then
       Timer1.Stop()
       Form3.Show()
       Me.Close()
    End If
 End sub

Update your project Shutdown mode setting. My Project > Application (tab) > Shutdown mode (drop down box) > When last form closes (item to select).

And then you should be fine

Upvotes: 2

Related Questions