Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a Splash Screen 1

Status
Not open for further replies.

tekrobg

Programmer
Oct 12, 2004
42
US
I am new to programming. I made a program and now want to include a splash screen. After reading and searching forums, I determined that I should use a splash screen via a Module and Sub Main. My code makes sense to me, but obviously I'm missing some things.

Here is my code for the Module:

vb/
Module Module1
Sub Main()
Dim splash As New FormSplash()
splash.Show()
End Sub
End Module
/vb

Here is my code for the splash screen form:

vb/
Private Sub FormSplash_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
Timer1.Stop()
Dim f As New Form1()
f.Show()
Me.Close()
End Sub
/vb

Timer1 is set at an interval of 3000 in the properties box.

Thanks for any help.
 
Module Startup
Public Sub Main()
dim frmSplashNew as New frmSplash()
dim frmMainNew as New frmMain()
frmSplashNew.showdialog()
frmMainNew.showdialog()
end main

put this code in a module called startup

then to set the startup object Sub Main, you do this in your Solution Explorer then
 
I did set the startup object to Sub Main. I tried that code, and it did not work.

Any other ideas?
 
What happens when the project starts up instead of the splash screen? try to set the time to a higher interval like 20000 every 10,000 is one second so maybe its just flashing by to quickly if you only have it set to 3000
 
MFritts, you had a small typo--needs to be "End Sub" instead of "End Main." Maybe that's it.
 
I thought the interval is measured in milliseconds; therefore, 3000 should equal 3 seconds. Is that correct?

When I run the application using my code, the splash screen loads and flickers once for a fraction of a second. I set the interval to 50,000 and it still just flickers once.

I assume I'm not using the Timer correctly.
 
What happens when yo get rid of the timer? That will tell you if it's the timer.

Or show the form modal (it's ok in .net, yes?)
 
After getting rid of the timer, it does the exact same thing. The splash screen flickers once and goes away.
 
Here is my code for the Module:

vb/
Module Module1
Sub Main()
Dim splash As New FormSplash()
splash.Show()
End Sub
End Module
/vb

Here is my code for the splash screen form:

vb/
Private Sub FormSplash_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
Timer1.Stop()
Dim f As New Form1()
f.Show()
Me.Close()
End Sub
/vb

Timer1 is set at an interval of 3000 in the properties box.
 
Yes, it's set to false in the property box.
 
Code:
Sub Main()
        Dim fs As New FormSplash()
        fs.Show() : Application.DoEvents()
        Threading.Thread.Sleep(3000)
        fs.Close()
        Dim fm As New Form1
        fm.ShowDialog()
End Sub
 
Forgot to add, try using the above, and remove the time and code from your splash form.
 
tekrobg, did you get it working? I did.

And I found RiverGuy's answer to be very cool..
Forget the timer.

And thanks for asking the question. I learned something too. ;-)
 
Thanks RiverGuy! Yes, I got that working, but there is still a problem. The splash works fine now. However, if I use fm.Show(), then Form1 flickers and disappears. If I use fm.ShowDialog(), then Form1 loads, but when I click a "Next" button on Form1 to go to Form2, the program ends. I didn't have this problem until dealing with this splash screen; it worked well before.

Any ideas?
 
When the application completes the code in Main the program ends. So as soon as Form1 closes, Main resumes and ends the program.

-Rick

----------------------
 
If you're going to run from a module instead of a form, then use showdialog. It stopps the code in module main from continuing to the next statement. Like show modal was in VB6.

.NET just works that way. I had a lot of troubles with how this worked.
 
Based on the above 2 responses, if the Sub Main continues after Form1 which ends the program, how do I stop this from happening so I can use multiple forms? My program is 5 forms in series connected with a "Next" button.

Also, I will gladly use ShowDialog, but how can I get rid of the sizing lines (///) in the bottom right-hand corner of the form?

One more multiple-part question, did I choose a poor method of using a splash screen? Should I NOT use a Module? I wasn't sure of the best way to do it, but after researching it, I found it should be the best method to perform initializations at the beginning of a program such as opening database connections, etc. Was I wrong?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top