Results 1 to 14 of 14

Thread: [RESOLVED] Splash Screen "Coding to make it Optional"

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2007
    Posts
    18

    Resolved [RESOLVED] Splash Screen "Coding to make it Optional"

    I'm writing a small program and it uses a Splash screen. This program will be accessible on various PC's. I was attempting to make it optional for users with powerful PC's. The following code is what I have and it yields an runtime error. This option is a ToolStripMenuItem. Is it possible to save this setting?

    VB.NET Code:
    1. If My.Application.SplashScreen.Enabled = True Then
    2.             Me.EnableSpToolStripMenuItem.Checked = False
    3.             My.Application.SplashScreen.Enabled = False
    4.         Else
    5.             Me.EnableSpToolStripMenuItem.Checked = True
    6.             My.Application.SplashScreen.Enabled = True  
    7.         End If
    Last edited by mykewall; Jul 25th, 2007 at 08:56 AM. Reason: Grammar

  2. #2
    Lively Member
    Join Date
    Jan 2007
    Posts
    95

    Re: Splash Screen "Coding to make it Optional"

    yeah! it is! you can save the settings in registry. here is the sample code, you can edit it according to your need:

    Add this on the top:
    vb Code:
    1. Dim YourApplicationName as String = "Your Application Name"
    2. Dim SplashScreenEnable as Boolean = True

    How To Save:
    vb Code:
    1. Private Sub SaveSettings(ByVal showsplashscreen as Boolean)
    2.         Dim ParentKey, Key As Microsoft.Win32.RegistryKey
    3.         Dim SubKey As String
    4.  
    5.         ParentKey = Microsoft.Win32.Registry.CurrentUser
    6.         SubKey = "Software\"+YourApplicationName
    7.  
    8.         Try
    9.             'Open the registry key.
    10.             Key = ParentKey.OpenSubKey(SubKey, True)
    11.             If Key Is Nothing Then 'if the key doesn't exist.
    12.                 Key = ParentKey.CreateSubKey(SubKey)
    13.             End If
    14.  
    15.             'Set the values.
    16.             Key.SetValue("ShowSplashScreen", showsplashscreen)
    17.  
    18.             MsgBox("Settings Saved.", MsgBoxStyle.Information)
    19.         Catch e As Exception
    20.             MsgBox("Cannot save the settings.\n\nError occurs in WriteRegistry" & e.Message, MsgBoxStyle.Information)
    21.         End Try
    22.     End Sub

    How To Load:
    vb Code:
    1. Private Sub LoadSettings()
    2.         Dim ParentKey, Key As Microsoft.Win32.RegistryKey
    3.         Dim SubKey As String
    4.  
    5.         ParentKey = Microsoft.Win32.Registry.CurrentUser
    6.         SubKey = "Software\"+YourApplicationName
    7.  
    8.         Try
    9.             'Open the registry key.
    10.             Key = ParentKey.OpenSubKey(SubKey, True)
    11.             If Key Is Nothing Then 'if the key doesn't exist
    12.                 Exit Sub
    13.             End If
    14.  
    15.             'Get the value.
    16.             SplashScreenEnable = Key.GetValue("ShowSplashScreen")
    17.  
    18.             ProfileLoaded = True
    19.         Catch e As Exception
    20.             'Console.WriteLine("Error occurs in ReadRegistry" & e.Message)
    21.         End Try
    22.     End Sub

    SplashScreenEnable will be the value (True or False)

    Call the LoadSettings function and you'll get the saved value.

    Rate my post if it helps you!

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2007
    Posts
    18

    Re: Splash Screen "Coding to make it Optional"

    Thank you very much. This seems very promising, but I do not know where to place this code to test it. I have a main form and a ApplicationEvents.vb file.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Splash Screen "Coding to make it Optional"

    Woah.... stop....
    Right-click the project and pull up it's properties. Go to the Settings Section and add a User level setting, call it ShowSplash, or whatever and set it to type boolean. The Default value is "True"

    Now.... in code Use the My keyword.... My.Settings.ShowSplash.... you get it and set it jsut like any property and it automatically saves.

    NOTE - this is for 2005... you didn't specify what version of VS you are using, so if it isn't 2005, this won't work.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Lively Member
    Join Date
    Jan 2007
    Posts
    95

    Re: Splash Screen "Coding to make it Optional"

    just put this in the man form file..

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jul 2007
    Posts
    18

    Re: Splash Screen "Coding to make it Optional"

    Ok. What does the ProfileLoaded boolean variable do? It's not declared.

  7. #7
    Lively Member
    Join Date
    Jan 2007
    Posts
    95

    Re: Splash Screen "Coding to make it Optional"

    oohh remove that variable.. i forget to remove that variable...

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jul 2007
    Posts
    18

    Re: Splash Screen "Coding to make it Optional"

    ok. however, it didn't work. I think I just didn't integrate it correctly. For instance, used
    vb Code:
    1. my.application.info.assemblyname
    in place of using;
    vb Code:
    1. Dim YourApplicationName as String = "Your Application Name"
    And the SplashScreenEnable variable was made global.

    The following is how I am trying to use the code you provided to helped me;

    In the Main Form | Menu | Item:
    vb Code:
    1. Private Sub mnuItemEnableSplashScreen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuItemEnableSplashScreen.Click
    2.         If Me.mnuItemEnableSplashScreen.Checked Then
    3.             Me.mnuItemEnableSplashScreen.Checked = False
    4.         Else
    5.             Me.mnuItemEnableSplashScreen.Checked = True
    6.         End If
    7.         My.Settings.SplashScreenEnable = Me.mnuItemEnableSplashScreen.Checked
    8.         SaveSettings(My.Settings.SplashScreenEnable)
    9.     End Sub

    In the Main form's Load sub:
    vb Code:
    1. LoadSettings()

  9. #9
    Lively Member
    Join Date
    Jan 2007
    Posts
    95

    Re: Splash Screen "Coding to make it Optional"

    according to your script, change the loadsettings subto this:
    Code:
    Private Sub LoadSettings()
            Dim ParentKey, Key As Microsoft.Win32.RegistryKey
            Dim SubKey As String
            ParentKey = Microsoft.Win32.Registry.CurrentUser
            SubKey = "Software\"+my.application.info.assemblyname
    
            Try
                'Open the registry key.
                Key = ParentKey.OpenSubKey(SubKey, True)
                If Key Is Nothing Then 'if the key doesn't exist
                    Exit Sub
                End If
    
                'Get the value.
                My.Settings.SplashScreenEnable = Key.GetValue("ShowSplashScreen")
    
            Catch e As Exception
                'Console.WriteLine("Error occurs in ReadRegistry" & e.Message)
            End Try
        End Sub

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Splash Screen "Coding to make it Optional"

    Ugh.... pick a spot. EITHER the REGISTRY... OR in application Settings.... don't try to mix the two... all the code above does is pull it out of the registry and stuff it into My.Settings..... still doesn't do any good... still need the value out of My.Settings in order to use it... so what's the point?

    use this code like you have it:
    Code:
          Private Sub mnuItemEnableSplashScreen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuItemEnableSplashScreen.Click
                  If Me.mnuItemEnableSplashScreen.Checked Then
                      Me.mnuItemEnableSplashScreen.Checked = False
                  Else
                      Me.mnuItemEnableSplashScreen.Checked = True
                  End If
                  My.Settings.SplashScreenEnable = Me.mnuItemEnableSplashScreen.Checked
                  SaveSettings(My.Settings.SplashScreenEnable)
              End Sub

    In the form load of the main form:

    Code:
    If my.Settings.ShowSplash Then
      'Load your splash screen and show it
    End If
    No complicated registry.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Jul 2007
    Posts
    18

    Re: Splash Screen "Coding to make it Optional"

    I'm sorry, but you lost me.
    "according to my script..."

    Is this an answer to my question or are you attempting to verify what my code should look like after the changes I said I made?

    The sub look actually like that, but my question remains...

    Myke

  12. #12
    Lively Member
    Join Date
    Jan 2007
    Posts
    95

    Re: Splash Screen "Coding to make it Optional"

    look,.... starting from the beginning:
    Code:
    ' This will save your settings
    Private Sub SaveSettings(ByVal showsplashscreen as Boolean)
            Dim ParentKey, Key As Microsoft.Win32.RegistryKey
            Dim SubKey As String
    
            ParentKey = Microsoft.Win32.Registry.CurrentUser
            SubKey = "Software\"+my.application.info.assemblyname
    
            Try
                'Open the registry key.
                Key = ParentKey.OpenSubKey(SubKey, True)
                If Key Is Nothing Then 'if the key doesn't exist.
                    Key = ParentKey.CreateSubKey(SubKey)
                End If
    
                'Set the values.
                Key.SetValue("ShowSplashScreen", showsplashscreen)
    
                MsgBox("Settings Saved.", MsgBoxStyle.Information)
            Catch e As Exception
                MsgBox("Cannot save the settings.\n\nError occurs in WriteRegistry" & e.Message, MsgBoxStyle.Information)
            End Try
    End Sub
    
    ' Now this will load
    Private Sub LoadSettings()
            Dim ParentKey, Key As Microsoft.Win32.RegistryKey
            Dim SubKey As String
            ParentKey = Microsoft.Win32.Registry.CurrentUser
            SubKey = "Software\"+my.application.info.assemblyname
    
            Try
                'Open the registry key.
                Key = ParentKey.OpenSubKey(SubKey, True)
                If Key Is Nothing Then 'if the key doesn't exist
                    Exit Sub
                End If
    
                'Get the value.
                My.Settings.SplashScreenEnable = Key.GetValue("ShowSplashScreen")
    
            Catch e As Exception
                'Console.WriteLine("Error occurs in ReadRegistry" & e.Message)
            End Try
    End Sub
    
    ' now, your menu item click event:
    Private Sub mnuItemEnableSplashScreen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuItemEnableSplashScreen.Click
            If Me.mnuItemEnableSplashScreen.Checked Then
                Me.mnuItemEnableSplashScreen.Checked = False
            Else
                Me.mnuItemEnableSplashScreen.Checked = True
            End If
            My.Settings.SplashScreenEnable = Me.mnuItemEnableSplashScreen.Checked
            SaveSettings(Me.mnuItemEnableSplashScreen.Checked)
    End Sub
    
    ' on form load
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            LoadSettings()
            
            If My.Settings.SplashScreenEnable Then
                ' Show Splash Code goes here!
            End If
    End Sub
    this is what you want to save your settings... i'm 100% sure that this will work!

    and never forget to rate! []

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Jul 2007
    Posts
    18

    Re: Splash Screen "Coding to make it Optional"

    OK, I did all that except for the If statement. However, techgnome offered a more desired approach which didn't change my original coding and it works.

    I will be creating another larger appliaction soon and will definitely apply your code to it's similar feature.

    Thanks a million extreme.aly & techgnome. Having support from guys like you would definitely motivate to me to give support back once I'm no longer a beginner...

  14. #14
    Lively Member
    Join Date
    Jan 2007
    Posts
    95

    Re: [RESOLVED] Splash Screen "Coding to make it Optional"

    well few days back, i was also a beginner but VBForum really help me alot in learning vb.net!

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