Close a form after x amount of time

  • Thread starter Thread starter mattgcon
  • Start date Start date
M

mattgcon

I have a popup form within my application that I want to show for only
about 10 seconds. On this form by the way has an AVI that plays. I want
the form to popup on click of a button and close after 10 seconds
automatically but can't figure out how to do it, does nayone know how
to do this?
 
Add a timer to the form, set it for 10 seconds, when it
goes off, in your event handler, close the form.

Robin S.
 
Here's one way using a timer:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim t As Timer = New Timer()
t.Interval = 10000
AddHandler t.Tick, AddressOf HandleTimerTick
t.Start()
End Sub

Private Sub HandleTimerTick()
Me.Close()
End Sub

Thanks,

Seth Rowe
 
Here's one way using a timer:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim t As Timer = New Timer()
t.Interval = 10000
AddHandler t.Tick, AddressOf HandleTimerTick
t.Start()
End Sub

Private Sub HandleTimerTick(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Me.Close()
End Sub

Thanks,

Seth Rowe
 
Robin,

I tried the timer thing, I placed it within the form load maybe that is
the wrong place to have it, but anyway, after the time the form didn't
go away.

here is my code
t.Interval = 100
t.Enabled = True
While t.Interval < 10000
t.Interval += 100
End While
frmAVI.Close()
 
I have a popup form within my application that I want to show for only
about 10 seconds. On this form by the way has an AVI that plays. I want
the form to popup on click of a button and close after 10 seconds
automatically but can't figure out how to do it, does nayone know how
to do this?

So everyone else is suggesting Timers. I was going to suggest that as
well, but I wanted to be different! ;)
Is there a way you can detect when the AVI stops playing? If so, you
could detect the end of the AVI and then close the form. This *might*
be better than a fixed time limit of 10 seconds, in cases where the
system hangs for 1 or 2 seconds while the AVI is playing (actuallly,
probably while it's loading).
Unfortunately, I don't know how to do that in code (never done AVI's in
VB). But it's a different suggestiong.
 
If he starts it as a process he could do:

dim p as System.Diagnostics.Process = Process.Start(..)
p.WaitfoExit()
me.Close()

I too have never messed with AVIs, hopefully the OP will share how he
starts it.

Thanks,

Seth Rowe
 
Seth,

Actually I didn't do anything special to start the AVI. I am using an
Animation Control that automatically starts the AVI for me.
I did the timer thing like that which was mention and it work perfectly
thank you
 
Back
Top