Results 1 to 6 of 6

Thread: Help with Splash Screen and Timer

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2002
    Location
    Georgia
    Posts
    27

    Help with Splash Screen and Timer

    Hi all,

    I need your assistence with a Splash Screen and A timer. I would like the timer to control how long the Splash Screen is Visable. I am using VB.net so I am not sure if the code for VB6 would work. Below is the code for my MDI Parent and if anyone could perhaps show me or tell me where the requested code is supposed to be I would greatly appriciate it. By the way the name of my Splash Screen form is "WelcomeScreen"

    Public Class Main
    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


    'OpenFileDialog1
    '
    Me.OpenFileDialog1.Filter = "txt files (*.txt)|*.txt|doc files (*.doc)|*.doc|All files (*.*)|*.*"
    Me.OpenFileDialog1.InitialDirectory = "C:"
    Me.OpenFileDialog1.Title = "Open"
    '
    'SaveFileDialog1
    '
    Me.SaveFileDialog1.CheckFileExists = True
    Me.SaveFileDialog1.CreatePrompt = True
    Me.SaveFileDialog1.FileName = "doc1"
    Me.SaveFileDialog1.Filter = "txt files (*.txt)|*.txt|doc files (*.doc)|*.doc|All files (*.*)|*.*"
    Me.SaveFileDialog1.InitialDirectory = "C:"
    Me.SaveFileDialog1.Title = "Save"
    '
    'PrintPreviewDialog1
    '
    Me.PrintPreviewDialog1.AutoScrollMargin = New System.Drawing.Size(0, 0)
    Me.PrintPreviewDialog1.AutoScrollMinSize = New System.Drawing.Size(0, 0)
    Me.PrintPreviewDialog1.ClientSize = New System.Drawing.Size(400, 300)
    Me.PrintPreviewDialog1.Document = Me.PrintDocument1
    Me.PrintPreviewDialog1.Enabled = True
    Me.PrintPreviewDialog1.Icon = CType(resources.GetObject("PrintPreviewDialog1.Icon"), System.Drawing.Icon)
    Me.PrintPreviewDialog1.Location = New System.Drawing.Point(376, 15)
    Me.PrintPreviewDialog1.MaximumSize = New System.Drawing.Size(0, 0)
    Me.PrintPreviewDialog1.Name = "PrintPreviewDialog1"
    Me.PrintPreviewDialog1.Opacity = 1
    Me.PrintPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty
    Me.PrintPreviewDialog1.Visible = False
    '
    'PrintDocument1
    '
    Me.PrintDocument1.DocumentName = CType(configurationAppSettings.GetValue("PrintDocument1.DocumentName", GetType(System.String)), String)
    '
    'PrintDialog1
    '
    Me.PrintDialog1.AllowPrintToFile = CType(configurationAppSettings.GetValue("PrintDialog1.AllowPrintToFile", GetType(System.Boolean)), Boolean)
    Me.PrintDialog1.AllowSelection = CType(configurationAppSettings.GetValue("PrintDialog1.AllowSelection", GetType(System.Boolean)), Boolean)
    Me.PrintDialog1.AllowSomePages = CType(configurationAppSettings.GetValue("PrintDialog1.AllowSomePages", GetType(System.Boolean)), Boolean)
    Me.PrintDialog1.Document = Me.PrintDocument1
    '
    'PageSetupDialog1
    '
    Me.PageSetupDialog1.AllowMargins = CType(configurationAppSettings.GetValue("PageSetupDialog1.AllowMargins", GetType(System.Boolean)), Boolean)
    Me.PageSetupDialog1.AllowOrientation = CType(configurationAppSettings.GetValue("PageSetupDialog1.AllowOrientation", GetType(System.Boolean)), Boolean)
    Me.PageSetupDialog1.AllowPaper = CType(configurationAppSettings.GetValue("PageSetupDialog1.AllowPaper", GetType(System.Boolean)), Boolean)
    Me.PageSetupDialog1.AllowPrinter = CType(configurationAppSettings.GetValue("PageSetupDialog1.AllowPrinter", GetType(System.Boolean)), Boolean)
    '
    'MenuItemALPHAROSTER
    '
    Me.MenuItemALPHAROSTER.Index = 0
    Me.MenuItemALPHAROSTER.Text = "Alpha Roster"
    '
    'MenuItemUNITSTRENGTH
    '
    Me.MenuItemUNITSTRENGTH.Index = 1
    Me.MenuItemUNITSTRENGTH.Text = "Unit Strength"
    '
    'Main
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.BackColor = System.Drawing.Color.Green
    Me.ClientSize = New System.Drawing.Size(792, 573)
    Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
    Me.IsMdiContainer = True
    Me.Menu = Me.MainMenu1
    Me.Name = "Main"
    Me.Text = "Main"
    Me.WindowState = System.Windows.Forms.FormWindowState.Maximized

    End Sub

    #End Region

    Private StreamToPrint As IO.StreamReader

    Private Sub MenuItemCascade_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuItemCascade.Click
    Me.LayoutMdi(MdiLayout.Cascade)
    End Sub

    Private Sub MenuItemClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuItemClose.Click
    Dim frm As Form
    For Each frm In Me.MdiChildren
    frm.Close()
    Next
    End Sub

    Private Sub MAINForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim ctl As Control
    Dim ctlMDI As MdiClient

    ' Loop through all of the form's controls looking
    ' for the control of type MdiClient.
    For Each ctl In Me.Controls
    Try
    ' Attempt to cast the control to type MdiClient.
    ctlMDI = CType(ctl, MdiClient)

    ' Set the BackColor of the MdiClient control.
    ctlMDI.BackColor = Me.BackColor

    Catch exc As InvalidCastException
    ' Catch and ignore the error if casting failed.
    End Try
    Next

    End Sub

    Private Sub MenuItemOpen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuItemOpen.Click
    Dim openFileDialog1 As New OpenFileDialog()

    openFileDialog1.InitialDirectory = "c:\"
    openFileDialog1.Filter = "txt files (*.txt)|*.txt|doc files (*.doc)|*.doc|All files (*.*)|*.*"
    openFileDialog1.FilterIndex = 1
    openFileDialog1.RestoreDirectory = True

    If openFileDialog1.ShowDialog() = DialogResult.OK Then
    openFileDialog1.OpenFile()

    End If

    End Sub

    Private Sub MenuItemPrintPreview_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuItemPrintPreview.Click
    PrintPreviewDialog1.ShowDialog()
    End Sub

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Here you go, I did a simple little example for you. form1 is the main form for your app, form2 will be your splash screen. You need to add a timer to form1. form1 should be the start up form.

    There are other ways to do this, this is just one.
    VB Code:
    1. Public Class Form1
    2.     Inherits System.Windows.Forms.Form
    3.  
    4. #Region " Windows Form Designer generated code "
    5.  
    6.     Dim frmTemp As Form2 'Make a reference to the splash here.
    7.  
    8.     Public Sub New()
    9.         MyBase.New()
    10.  
    11.         'This call is required by the Windows Form Designer.
    12.         InitializeComponent()
    13.  
    14.         frmTemp = New Form2() 'Create an instance of the splash
    15.  
    16.         Timer1.Interval = 4000 'Set how long you want it to show for.
    17.         Timer1.Start() 'Start the timer.
    18.         frmTemp.ShowDialog() 'Show the form modally.
    19.  
    20.         'Add any initialization after the InitializeComponent() call
    21.  
    22.     End Sub
    23.  
    24.     'Form overrides dispose to clean up the component list.
    25.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    26.         If disposing Then
    27.             If Not (components Is Nothing) Then
    28.                 components.Dispose()
    29.             End If
    30.         End If
    31.         MyBase.Dispose(disposing)
    32.     End Sub
    33.  
    34.     'Required by the Windows Form Designer
    35.     Private components As System.ComponentModel.IContainer
    36.  
    37.     'NOTE: The following procedure is required by the Windows Form Designer
    38.     'It can be modified using the Windows Form Designer.  
    39.     'Do not modify it using the code editor.
    40.     Friend WithEvents Timer1 As System.Windows.Forms.Timer
    41.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    42.         Me.components = New System.ComponentModel.Container()
    43.         Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
    44.         '
    45.         'Timer1
    46.         '
    47.         '
    48.         'Form1
    49.         '
    50.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    51.         Me.ClientSize = New System.Drawing.Size(292, 266)
    52.         Me.Name = "Form1"
    53.         Me.Text = "Form1"
    54.  
    55.     End Sub
    56.  
    57. #End Region
    58.  
    59.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    60.         Timer1.Stop() 'Stop the timer
    61.         frmTemp.Hide() 'Hide the splash
    62.         frmTemp.Dispose() 'Now dispose of the splash, no longer needed.
    63.     End Sub
    64. End Class

  3. #3
    New Member
    Join Date
    Sep 2002
    Location
    Raleigh, NC
    Posts
    2

    RE:

    This is the easiest way to it:

    1. add your timer to the spash form (Timer1)
    2. Add the below code.


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

    'Call frmMain
    Dim f As frmMain = New frmMain()
    Me.Hide()
    f.Show()
    End Sub

    This will show the splash screen and then move to the main form and hide the splash... easy?? right??

  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    That is easy, but the whole purpose of the splash screen is to give the user something to look at while your app is loading. So loading your app after you get rid of the splash screen isn't good because the user now has to wait longer when you could have been taking care of it in the background.

    Sorry if this doesn't make sense. I am really hung over from last night.

  5. #5
    Lively Member
    Join Date
    Jul 2003
    Posts
    93
    Hellswraith,

    Question on your response with the simple example. I'm trying to show a splash screen as a combobox is being filled. Where exactally would I put the call to the sub that fills the combo? Presently I have the splash screen showing for the interval of the timer and then the splash closes and the app just hangs until the fillcombo processes. I'm missing something & hope you can help.


    #Region " Windows Form Designer generated code "

    Dim frmSplash As New Splash()

    Public Sub New()
    MyBase.New()

    'This call is required by the Windows Form Designer.
    InitializeComponent()
    frmSplash = New Splash()
    Timer1.Interval = 40000
    Timer1.Start()
    frmSplash.ShowDialog()
    'Add any initialization after the InitializeComponent() call
    Call subFillCombo() 'Where does this go??

    End Sub

    (Rest of Windows Form Designer generated code)

    # End Region

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

    Timer1.Stop()
    frmSplash.Hide()
    frmSplash.Dispose()

    End Sub

    Thanks

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Here is one to call a function from splash screen , and disappear when it's done the job .
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width