9 Replies - 4613 Views - Last Post: 05 January 2009 - 07:58 AM Rate Topic: -----

#1 steveshergill  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 29-December 08

countdown timer

Posted 04 January 2009 - 12:12 PM

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

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


Is This A Good Question/Topic? 0
  • +

Replies To: countdown timer

#2 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: countdown timer

Posted 04 January 2009 - 12:19 PM

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

Me.Close()


This post has been edited by Core: 04 January 2009 - 12:20 PM

Was This Post Helpful? 0
  • +
  • -

#3 kryton46  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 44
  • Joined: 29-December 08

Re: countdown timer

Posted 04 January 2009 - 12:21 PM

I use KISS :P

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:

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




View Poststeveshergill, on 4 Jan, 2009 - 11:12 AM, said:

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

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

Was This Post Helpful? 0
  • +
  • -

#4 steveshergill  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 29-December 08

Re: countdown timer

Posted 04 January 2009 - 12:38 PM

View Postkryton46, on 4 Jan, 2009 - 11:21 AM, said:

I use KISS :P

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:

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




View Poststeveshergill, on 4 Jan, 2009 - 11:12 AM, said:

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

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?
Was This Post Helpful? 0
  • +
  • -

#5 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: countdown timer

Posted 04 January 2009 - 12:41 PM

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

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: 04 January 2009 - 12:42 PM

Was This Post Helpful? 0
  • +
  • -

#6 kryton46  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 44
  • Joined: 29-December 08

Re: countdown timer

Posted 04 January 2009 - 12:54 PM

You kissed my KISS :P

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

View PostCore, on 4 Jan, 2009 - 11:41 AM, said:

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

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



Change Form2 to the name of your main working form.

Was This Post Helpful? 0
  • +
  • -

#7 steveshergill  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 29-December 08

Re: countdown timer

Posted 04 January 2009 - 02:32 PM

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
Was This Post Helpful? 0
  • +
  • -

#8 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: countdown timer

Posted 04 January 2009 - 02:38 PM

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.
Was This Post Helpful? 0
  • +
  • -

#9 steveshergill  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 29-December 08

Re: countdown timer

Posted 04 January 2009 - 04:40 PM

thanks for every1s help. really appreciate it. the timer problem has no been resolved
Was This Post Helpful? 0
  • +
  • -

#10 dbasnett  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 109
  • View blog
  • Posts: 605
  • Joined: 01-October 08

Re: countdown timer

Posted 05 January 2009 - 07:58 AM

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

		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


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1