Simple Form Question

  • Thread starter Thread starter Harry Simpson
  • Start date Start date
H

Harry Simpson

I've got a Spalsh screen that loads first and enables a timer. I want to
wait a second then go to the main form and dispose of the Splash screen to
save memory - also to avoid having to close two forms on exit.

Seems like it is very hard to refer to another form in CF apps.....
The code below ends the entire application. If i try to reference Splash
form from the NewForm the application can't see it so therefore i can't call
its Close/Dispose method.
What am i missing here?

On the Splash forms code:

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

Timer1.Enabled = True

End Sub

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

Dim NewForm As New Form1

NewForm.Show()

Me.Close()

End Sub
 
The way that's written, every time the timer ticks you are declaring a new
instance of Form1 and closing the main form.

Why not put the timer on the other form (the splash) and close it after 2
seconds or something?
 
William,

What you suggest is what i'm trying to do. The timer is on the Splash
screen. On load it enables, ticks for 2 seconds, creates and shows the next
form and tries to destroy itself (me.close)

It ends up closing the entire app as written.

Harry
 
The problem is that your app is probably calling Application.Run(new
SplashForm)

This puts the app message pump on that form and when it dies, the pump dies,
and Sub Main then exits and the app ends. You need to either start the
mesaage pump with the main form or chain them together. I'd probably try
something like this pseudocode:

Sub Main
Application.Run(new SplashForm)
Application.Run(new MainForm)
End Sub

Sub SplashForm
timer = new Timer
timer.Interval = 1000
timer enabled = true
End Sub

Sub Timer_Tick
Me.Close
End Sub
 
That worked well Chris, Thanks!!

The
Sub Main()

Application.Run(New Form1)

Application.Run(New Splash)

End Sub

is so much more intuitive to me than the

Dim NewForm as New Form1

NewForm.show



Harry
 
Glad it worked.

Just make sure you understand *why* that code works and the original didn't,
if you don't play with it a bit or ask us. Understanding the app message
pump and window management is key to both development and debugging.
 
Chris,

Think i need sleep....but aside from that, for some reason it's not working
now. When i run this SIMPLE code all i get is Splash loaded and shown for
two seconds and then the regular PPC screen....never see the Form1 screen.

Two Forms:
Form1
Splash
****************************************************************************
*****
Module w/Sub Main
as the start:

Module Module1
Sub Main()
Application.Run(New Splash)
Application.Run(New Form1)
End Sub

End Module
****************************************************************************
*****
Then on the Splash form:

a timer1 set to 2000 disabled.

Private Sub Splash_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
End Sub

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

Any ideas?
Harry
 
In fact after the Splash screen disappears, and i go to memory-running
programs i see Form1 in memory and there's even a SIP shortcut (brown
keyborad icon) that appears.

Harry
 
You need to make sure the first form is getting fully killed, not just
minimized. If it doesn't die, then the message pump won't exit and you'll
never get back to Main where you load up a new pump and form.
 
Back
Top