Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 244,305 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 780 people online right now. Registration is fast and FREE... Join Now!




countdown timer

 
Reply to this topicStart new topic

countdown timer

steveshergill
4 Jan, 2009 - 11:12 AM
Post #1

New D.I.C Head
*

Joined: 29 Dec, 2008
Posts: 15

I have created a splashscreen which i want to close after 3 seconds and open form1. The problem I am having is that it keeps opening a new form1 every 3 seconds. help please

CODE
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim FormToOpen As Type
        FormToOpen = GetType(Form1)
        Dim frm As Form = CType(Activator.CreateInstance(FormToOpen), Form)
        frm.Show()
      

    End Sub
End Class


User is offlineProfile CardPM
+Quote Post


Core
RE: Countdown Timer
4 Jan, 2009 - 11:19 AM
Post #2

using DIC.Mod.Core;
Group Icon

Joined: 8 Dec, 2008
Posts: 1,780



Thanked: 139 times
Dream Kudos: 350
Expert In: Software Development, Software Testing/Debugging

My Contributions
Close the main form (splash screen) after the form was shown:

CODE

Me.Close()


This post has been edited by Core: 4 Jan, 2009 - 11:20 AM
User is offlineProfile CardPM
+Quote Post

kryton46
RE: Countdown Timer
4 Jan, 2009 - 11:21 AM
Post #3

New D.I.C Head
Group Icon

Joined: 29 Dec, 2008
Posts: 22



Thanked: 2 times
Dream Kudos: 50
My Contributions
I use KISS tongue.gif

Make sure your start up form is set to your main form, ie. not the splash screen and put this code in your form load method:

CODE

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

        'show splash screen
        Me.Hide()
        Dim frmSplash As New Splash_screen
        frmSplash.Show()
        frmSplash.Update()
        '5 second delay to show splash screen
        System.Threading.Thread.Sleep(5000)
        frmSplash.Close()
        Me.Visible = True

End Sub



QUOTE(steveshergill @ 4 Jan, 2009 - 11:12 AM) *

I have created a splashscreen which i want to close after 3 seconds and open form1. The problem I am having is that it keeps opening a new form1 every 3 seconds. help please

CODE
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim FormToOpen As Type
        FormToOpen = GetType(Form1)
        Dim frm As Form = CType(Activator.CreateInstance(FormToOpen), Form)
        frm.Show()
      

    End Sub
End Class



User is offlineProfile CardPM
+Quote Post

steveshergill
RE: Countdown Timer
4 Jan, 2009 - 11:38 AM
Post #4

New D.I.C Head
*

Joined: 29 Dec, 2008
Posts: 15

QUOTE(kryton46 @ 4 Jan, 2009 - 11:21 AM) *

I use KISS tongue.gif

Make sure your start up form is set to your main form, ie. not the splash screen and put this code in your form load method:

CODE

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

        'show splash screen
        Me.Hide()
        Dim frmSplash As New Splash_screen
        frmSplash.Show()
        frmSplash.Update()
        '5 second delay to show splash screen
        System.Threading.Thread.Sleep(5000)
        frmSplash.Close()
        Me.Visible = True

End Sub



QUOTE(steveshergill @ 4 Jan, 2009 - 11:12 AM) *

I have created a splashscreen which i want to close after 3 seconds and open form1. The problem I am having is that it keeps opening a new form1 every 3 seconds. help please

CODE
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim FormToOpen As Type
        FormToOpen = GetType(Form1)
        Dim frm As Form = CType(Activator.CreateInstance(FormToOpen), Form)
        frm.Show()
      

    End Sub
End Class



what do you mean by mainform? Do you mean form1?
User is offlineProfile CardPM
+Quote Post

Core
RE: Countdown Timer
4 Jan, 2009 - 11:41 AM
Post #5

using DIC.Mod.Core;
Group Icon

Joined: 8 Dec, 2008
Posts: 1,780



Thanked: 139 times
Dream Kudos: 350
Expert In: Software Development, Software Testing/Debugging

My Contributions
For your splashscreen, just use the following code in the timer:

CODE

Dim form2 As New Form2
form2.Show()
Me.Close()


Change Form2 to the name of your main working form.

This post has been edited by Core: 4 Jan, 2009 - 11:42 AM
User is offlineProfile CardPM
+Quote Post

kryton46
RE: Countdown Timer
4 Jan, 2009 - 11:54 AM
Post #6

New D.I.C Head
Group Icon

Joined: 29 Dec, 2008
Posts: 22



Thanked: 2 times
Dream Kudos: 50
My Contributions
You kissed my KISS tongue.gif

This has got to be the cleanest and neatest solution for splash screens, txs Core.

QUOTE(Core @ 4 Jan, 2009 - 11:41 AM) *

For your splashscreen, just use the following code in the timer:

CODE

Dim form2 As New Form2
form2.Show()
Me.Close()


Change Form2 to the name of your main working form.


User is offlineProfile CardPM
+Quote Post

steveshergill
RE: Countdown Timer
4 Jan, 2009 - 01:32 PM
Post #7

New D.I.C Head
*

Joined: 29 Dec, 2008
Posts: 15

this doesnt seem to work. I have set the properties to enabled true and interval 5000. When i run it, it just closes everything down. please help
User is offlineProfile CardPM
+Quote Post

Core
RE: Countdown Timer
4 Jan, 2009 - 01:38 PM
Post #8

using DIC.Mod.Core;
Group Icon

Joined: 8 Dec, 2008
Posts: 1,780



Thanked: 139 times
Dream Kudos: 350
Expert In: Software Development, Software Testing/Debugging

My Contributions
Most likely it is because the splash screen is the first form in your application. So, if your project settings are set to default, the application will shutdown when first form closes. So, as you close the first form, the applications closes too. To change this, right click on the project name in Solution Explorer window and select Properties. Change the Shutdown Mode property to When last form closes.
User is offlineProfile CardPM
+Quote Post

steveshergill
RE: Countdown Timer
4 Jan, 2009 - 03:40 PM
Post #9

New D.I.C Head
*

Joined: 29 Dec, 2008
Posts: 15

thanks for every1s help. really appreciate it. the timer problem has no been resolved

User is offlineProfile CardPM
+Quote Post

dbasnett
RE: Countdown Timer
5 Jan, 2009 - 06:58 AM
Post #10

D.I.C Head
**

Joined: 1 Oct, 2008
Posts: 224



Thanked: 13 times
My Contributions
WOW! .Net has a mechanism already in place for controlling the amount of time a splash screen is shown...


in the project settings, set the Splash Screen to your splash screen

in ApplicationEvents.vb

CODE
        Protected Overrides Function OnInitialize _
                (ByVal commandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String)) _
                As Boolean
            ' Set the display time to 3000 milliseconds (3 seconds).
            Me.MinimumSplashScreenDisplayTime = 3000
            Return MyBase.OnInitialize(commandLineArgs)
        End Function

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 06:12PM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month