-
[2005] open at startup+checkbox
kk i have the following code to have a checkbox to have the program automatically open at startup or not:
VB Code:
Dim key As Microsoft.Win32.RegistryKey
key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
If CheckBox3.Checked = True Then
key.SetValue("Notes", Application.ExecutablePath)
MsgBox("Set '" & CType(key.GetValue("Notes"), String) & "' to open at system startup.")
Else
key.DeleteValue("Notes")
End If
well it works perfectly fine but i noticed a little problem... when re-loading the application, i noticed that the checkbox is set back to the default setting (unchecked)
i want the app to check, as soon as the form is loaded, to see if the app is already in the registry to run at startup, and if so then have the checkbox checked, but if not then have it unchecked
all help would be appreciated
thanks
cheers,
Phil.
-
Re: [2005] open at startup+checkbox
Well of course it is going to do that...how will the form remember the checked value if it is reloaded? You will need to read back into the form the original value you intend.
Makes sense no ?
-
Re: [2005] open at startup+checkbox
i don't get what your going at...
can i get some bits of code please?
-
Re: [2005] open at startup+checkbox
Think about it. Every time you start the application the CheckBox is going to be whatever you set it to at design time. If you want it to reflect the setting in the registry then you have to tell it so. You have to check the registry to see if that value is there and set the state of the CheckBox accordingly. That's what JAKSupport is saying.
Alternatively you could bind the CheckBox to an application setting but I'd probably recommend against that because then it is conceivable, if unlikely, that the two could get out of sync.
-
Re: [2005] open at startup+checkbox
yeah well that's what i was trying to do, how can i make it check to see if the value exists?
-
Re: [2005] open at startup+checkbox
The RegistryKey.GetValue method will return the actual value if a registry value with the specifed name exists or Nothing if it doesn't. You simply have to set the Checked property of your CheckBox to (GetValue IsNot Nothing).
-
Re: [2005] open at startup+checkbox
here's what i have:
VB Code:
Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
SaveSetting("Notes", "Save", "Open Startup", CheckBox3.Checked)
End Sub
VB Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
CheckBox3.Checked = GetSetting("Notes", "Save", "Open Startup", "False")
End Sub
It doesn't save the value of the checkbox... it just puts the default one
-
Re: [2005] open at startup+checkbox
Noone said anything about using SaveSetting or GetSetting. They have absolutely nothing to do with the Run registry key so they are no help whatsoever in this situation. Let me start again.
When you shutdown your app you will be testing whether the check box is checked, correct?
If it is checked then you open the Run key and use SetValue to place a value for your app in the regsitry, correct?
If it is not checked then you have to Open the Run key and call DeleteValue to remove the value for your application, correct?
Now, when you start your app you have to open the Run key and call GetValue to see if there is a value there for your app. If GetValue returns a value then you need to check your check box. If GetValue returns Nothing then there is no value there so you don't check the check box.
-
Re: [2005] open at startup+checkbox
oh ic what you mean... but how would i make it do so?
-
Re: [2005] open at startup+checkbox
In your very first post you've used GetValue so you already know how to use it. All you have to do is compare its return value to Nothing. That will give you True or False. The Checked property of a CheckBox requires a True or False value.
-
Re: [2005] open at startup+checkbox
ok i completely understand what you mean, but how to compare it?
-
Re: [2005] open at startup+checkbox
here an example
VB Code:
Dim key As Microsoft.Win32.RegistryKey
key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
If key.GetValue("Notes", Nothing) IsNot Nothing Then
MessageBox.Show("The key exist")
Else
MessageBox.Show("The key does not exist")
End If
-
Re: [2005] open at startup+checkbox
kk thanks a lot it was the nothing part i was looking for..
except that the "IsNot Nothing Then" part is underlined blue and says end of statement expected :ehh:
-
Re: [2005] open at startup+checkbox
if you have exacly the same way i showed you it shouldn't be underlined. Post that part.
-
Re: [2005] open at startup+checkbox
The 'IsNot' keyword is new in VB 2005. If you're using 2005 then it's valid. Are you actually using an earlier? If so then you need to use:rather than:If you're using 2005 as your post says then it will work exactly as VBDT has suggested, exactly as VBDT says.
-
Re: [2005] open at startup+checkbox
Quote:
If you're using 2005 as your post says then it will work exactly as VBDT has suggested, exactly as VBDT says.
Are you trying to make a fun of me? :eek: No, I am not serious! ;) :D Thanks for correcting me; I actually learned a lot from you. :wave: English is not my native language and I am too lazy to check my spelling so there it goes. :rolleyes:
-
Re: [2005] open at startup+checkbox
Quote:
Originally Posted by VBDT
Are you trying to make a fun of me? :eek: No, I am not serious! ;) :D Thanks for correcting me; I actually learned a lot from you. :wave: English is not my native language and I am too lazy to check my spelling so there it goes. :rolleyes:
You suggested a way to make it work. You said that it would work exactly as you had suggested. I'm saying that, exactly as you said, it will work exactly as you had suggested. If I was making fun you'd know. ;)
-
Re: [2005] open at startup+checkbox
I know! I am just playing with you. ;) This is what happens when one gets bored.
-
Re: [2005] open at startup+checkbox
well, thanks but i have the .NET version... isn't .NET and 2005 the same version? :confused:
it's still underlined
-
Re: [2005] open at startup+checkbox
.Net and 2005 are not the same thing. There are 3 different versions of .Net out there
.Net 1.0 2002
.Net 1.1 2003
.Net 2.0 2005
You can determine what version you are using by going to Help -> About. It will tell you there.
-
Re: [2005] open at startup+checkbox
-
Re: [2005] open at startup+checkbox
Then you need to use example 2 in post 15.
-
Re: [2005] open at startup+checkbox
Quote:
Originally Posted by mpdeglau
Then you need to use example 2 in post 15.
The first example is valid for .NET 1.x or .NET 2.0. The second example is valid for .NET 2.0 only.
-
Re: [2005] open at startup+checkbox
oops. Sorry about that. That's what I meant. Memory of a goldfish. :blush:
-
Re: [2005] open at startup+checkbox
oh sweet thanks then it works