|
-
Jul 20th, 2007, 08:32 AM
#1
Thread Starter
Junior Member
[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
Last edited by mykewall; Jul 25th, 2007 at 08:56 AM.
Reason: Grammar
-
Jul 20th, 2007, 11:27 AM
#2
Lively Member
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!
-
Jul 25th, 2007, 09:27 AM
#3
Thread Starter
Junior Member
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.
-
Jul 25th, 2007, 09:36 AM
#4
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
-
Jul 25th, 2007, 09:40 AM
#5
Lively Member
Re: Splash Screen "Coding to make it Optional"
just put this in the man form file..
-
Jul 25th, 2007, 09:45 AM
#6
Thread Starter
Junior Member
Re: Splash Screen "Coding to make it Optional"
Ok. What does the ProfileLoaded boolean variable do? It's not declared.
-
Jul 25th, 2007, 09:51 AM
#7
Lively Member
Re: Splash Screen "Coding to make it Optional"
oohh remove that variable.. i forget to remove that variable...
-
Jul 25th, 2007, 10:54 AM
#8
Thread Starter
Junior Member
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:
-
Jul 25th, 2007, 11:22 AM
#9
Lively Member
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
-
Jul 25th, 2007, 11:32 AM
#10
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
-
Jul 25th, 2007, 11:33 AM
#11
Thread Starter
Junior Member
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
-
Jul 25th, 2007, 01:54 PM
#12
Lively Member
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! [ ]
-
Jul 25th, 2007, 02:09 PM
#13
Thread Starter
Junior Member
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...
-
Jul 25th, 2007, 02:12 PM
#14
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|