[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:
If My.Application.SplashScreen.Enabled = True Then
Me.EnableSpToolStripMenuItem.Checked = False
My.Application.SplashScreen.Enabled = False
Else
Me.EnableSpToolStripMenuItem.Checked = True
My.Application.SplashScreen.Enabled = True
End If
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:
Dim YourApplicationName as String = "Your Application Name"
Dim SplashScreenEnable as Boolean = True
How To Save:
vb Code:
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\"+YourApplicationName
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
How To Load:
vb Code:
Private Sub LoadSettings()
Dim ParentKey, Key As Microsoft.Win32.RegistryKey
Dim SubKey As String
ParentKey = Microsoft.Win32.Registry.CurrentUser
SubKey = "Software\"+YourApplicationName
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.
SplashScreenEnable = Key.GetValue("ShowSplashScreen")
ProfileLoaded = True
Catch e As Exception
'Console.WriteLine("Error occurs in ReadRegistry" & e.Message)
End Try
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!
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.
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
Re: Splash Screen "Coding to make it Optional"
just put this in the man form file..
Re: Splash Screen "Coding to make it Optional"
Ok. What does the ProfileLoaded boolean variable do? It's not declared.
Re: Splash Screen "Coding to make it Optional"
oohh remove that variable.. i forget to remove that variable...
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:
my.application.info.assemblyname
in place of using;
vb Code:
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:
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 Main form's Load sub:
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
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
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
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! [;)]
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...
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!