Solved

Splash Screen - how to?

Posted on 2004-10-12
9
236 Views
Last Modified: 2010-04-23
How do I make a splash screen that shows while app is starting or for a few seconds?

It should just be a jpeg (no borders, title bar, icon etc) with some (variable) text labels on it.

After app has finished loading (or after 3-4 seconds) the first form should be showed.
0
Comment
Question by:netslt
9 Comments
 
LVL 28

Expert Comment

by:iboutchkine
ID: 12291797
'add new form fmSplash ( it will be your splash screen)

Imports System.Threading

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(120, 108)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Button1"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region
    Shared thrSplash As Thread


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim clsSplash As New cThreadSplash
        thrSplash = New Thread(New ThreadStart(AddressOf clsSplash.thSplashDisplay))
        thrSplash.Start()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox("main form")
    End Sub
End Class
Public Class cThreadSplash
    Public Sub thSplashDisplay()
        Dim f As New fmSplash
        f.Text = "Splash Screen"
        Try
            f.ShowDialog()
        Catch es As ThreadAbortException
            Thread.ResetAbort()
        Catch
        End Try
    End Sub
End Class
0
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12292316
a little modification with a timer.

Public Class cThreadSplash

   Dim WithEvents T As New Timers.Timer
   Dim f As New fmSplash

   Public Sub thSplashDisplay()

      T.Interval = 3000 ' 3 seconds
      T.Start()

      f.Text = "Splash Screen"
      Try
         f.ShowDialog()
      Catch es As ThreadAbortException
         Thread.ResetAbort()
      Catch
      End Try
   End Sub
   Private Sub T_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles T.Elapsed
      f.Close()
   End Sub
End Class

GL
0
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12292327
Sorry i forgget "t.stop"

Private Sub T_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles T.Elapsed
      f.Close()
      t.stop
   End Sub
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:netslt
ID: 12292408
Thanks!

So do I have to call

  Public Sub thSplashDisplay()

from my main form, it will display the splash form, and then after defined time the main form will show again?

And I also put   Public Sub thSplashDisplay() etc. in my main form?

And how does thSplashDisplay show a form instead of text?
0
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12292586
you have to add to project a new form called "fmSplash "

For hide border add this line into "fmSplash"
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None

f.Text = "Splash Screen" <- Mean the title of form "Splash Screen"

If you put the thSplashDisplay method on FORM_LOAD event  it will just showed on load.
GL
0
 

Author Comment

by:netslt
ID: 12292829
When I add

thSplashDisplay()

within the  Form1_Load

I get an error that it can not access a member that has not been declared as "shared" and that I have to use an object reference.

So what do I do?
0
 
LVL 10

Accepted Solution

by:
Hans Langer earned 200 total points
ID: 12293206
Where you got this error?

you have to add those line

'This line in the class declaration
Private thrSplash As Thread

'in FORM1_LOAD
Dim clsSplash As New cThreadSplash
thrSplash = New Thread(New ThreadStart(AddressOf clsSplash.thSplashDisplay))
thrSplash.Start()
0
 

Author Comment

by:netslt
ID: 12295761
This works perfectly - thanks a lot!

One last question - do you know how to center the splash screen on the screen?

0
 
LVL 18

Assisted Solution

by:armoghan
armoghan earned 50 total points
ID: 12295952
that is how you center a form
this.StartPosition = FormStartPosition.CenterScreen;


also see the following link
http://www.csharphelp.com/archives2/archive355.html
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question