-
Nov 15th, 2012, 12:01 AM
#1
Thread Starter
Member
Help with Project (Saving and Updating)
Hi.
This is my Project:
https://sourceforge.net/p/xtrmstpwtch
I'd like to add new features to it.
->One of which is Saving Settings
I've added a Theme for the app, and would like the App to be able to remember the Theme that was selected before Exiting, so that it can be loaded as the initial one next time.
For this I've got a Combo box which lists the Theme Name and a Check box which the user can select to remember the selected theme.
Without the Saving settings option, the theme works.. but I wasn't able to figure out how to get the Saving Settings of a Check box to work
I did take a look at a few links, but most of them were about saving Strings and Text
-> Secondly, I'd like to add an Option to Check for Updates to the app.
Is this possible If I'm uploading my Projects/Apps to Sourceforge? If Yes then I'd appreciate a few ti
or do I need a Personal Website/FTP Server?
Thanks..
-
Nov 15th, 2012, 08:53 AM
#2
Re: Help with Project (Saving and Updating)
Add a new User level setting... make it a boolean type... bind it to your checkbox...
select the checkbox, go to the properties... under the Data grouping, there's an "(ApplicationSettings)" entry... expand it... select the Checked entry... and in the drop down, select the Setting you just created... done... now your checkbox is linked to the setting... so when the user turns it on, the value will be saved in the setting... then when the app loads, it checks the setting to see if it should load the theme, and then load it if it has been set...
-tg
-
Nov 15th, 2012, 10:57 AM
#3
Thread Starter
Member
-
Nov 15th, 2012, 11:42 AM
#4
Re: Help with Project (Saving and Updating)
I followed my steps, it worked fine, I followed your steps, it worked fine for me too... so I'm not sure what to tell you.
do this... go back to the settings page... and remove it... save everything... go back to the checkbox, and try to re-create the setting from that end like you did... I wonder if not savign the new setting is what caused it to not show and so when you then created the secondone, it got an error because of two settings with one name...
Or... after creating the setting, SAVE every thing Ctrl+Shift+S ... then try the binding again.
-tg
-
Nov 15th, 2012, 02:58 PM
#5
Thread Starter
Member
Re: Help with Project (Saving and Updating)
Originally Posted by techgnome
do this... go back to the settings page... and remove it... save everything... go back to the checkbox, and try to re-create the setting from that end like you did... I wonder if not savign the new setting is what caused it to not show and so when you then created the secondone, it got an error because of two settings with one name...
Or... after creating the setting, SAVE every thing Ctrl+Shift+S ... then try the binding again.
-tg
I Deleted the Setting that I created Manually and hit Ctrl+Shift+S, This fixed the error that was being thrown.
I have left the Check box to be Unchecked by default.
I had to do some research about Settings as I've never used them before..
This is the code that I then wrote..
Code:
Private Sub BtnApply_Click(sender As System.Object, e As System.EventArgs) Handles btnApply.Click
If cbothemes.SelectedItem = "Misty Rose" Then
Stopwatch.MistyRose()
End If
If chbYes.Checked = True Then
My.Settings.ThemeRem = True
My.Settings.Save()
End If
End Sub
BtnApply = Button to Apply the Theme
cbothemes = Combo box that lists the Themes
chbYes = Check box that says Yes. If checked the Settings should be saved and loaded next time the Form is loaded.
I tried this way too..
Code:
Private Sub BtnApply_Click(sender As System.Object, e As System.EventArgs) Handles btnApply.Click
If cbothemes.SelectedItem = "Misty Rose" Then
Stopwatch.MistyRose()
End If
If chbYes.Checked = True Then
My.Settings.ThemeRem = Me.chbYes.Checked
My.Settings.Save()
Else
My.Settings.Save()
End If
End Sub
Unfortunately both methods didn't work out..
What I did notice this does is that it Saves the State of the Check box i.e: Checked/Unchecked..
-
Nov 15th, 2012, 03:06 PM
#6
Re: Help with Project (Saving and Updating)
Ummm.... yes... I though that's what you wanted... what is it that you want to save?
you said "I wasn't able to figure out how to get the Saving Settings of a Check box to work" ... now it does... what is it you're looking for?
-tg
-
Nov 16th, 2012, 12:19 AM
#7
Thread Starter
Member
Re: Help with Project (Saving and Updating)
Actually what I wanted was the Theme to be Remembered when the Check box is Checked..
For example: If the user selects "Misty Rose" theme and checks the check box, next time the form is loaded, the Theme "Misty Rose" should be loaded and not the Default..
-
Nov 16th, 2012, 08:10 AM
#8
Re: Help with Project (Saving and Updating)
See... whren you said "I did take a look at a few links, but most of them were about saving Strings and Text" and "I wasn't able to figure out how to get the Saving Settings of a Check box to work" I took that to mean you wanted to save the checkbox to a setting... you implied that you already had the setting for the theme name (as it's a string, and you pointed out, you found examples of that)... You didn't say you wanted to save the theme... Even still, you now know how to create a setting, assign something to it and save it... if you want to save what's in the combobox... it's a string... so.......
-tg
-
Nov 16th, 2012, 10:38 AM
#9
Thread Starter
Member
Re: Help with Project (Saving and Updating)
Alright, so this is what I did..
I chose to work with Boolean rather than String in the settings, as I'm new to it.. it seemed difficult..
Perhaps once I'm used to working with Settings, I'll think about changing.
So, I replaced the Combo box with two Radio buttons.
One named: Default and the Other: Misty Rose
When the user Checks the Radio Button, the Respective theme is applied.
I did the same, I went on to bind the Radio buttons with settings. Each with its own..
Now... When the Theme is selected, then the form is closed..
Next time it opens up.. the Theme is still unchanged (default).... no changes.
But... when I open up the Settings Form the Theme that was last selected is applied.
I thought I needed to command the Start-up form to load the settings..
So I put this code in the Event Handler for the Start-up form:
Code:
If My.Settings.MistyRoseTheme.Equals(True) Then
MistyRose()
ElseIf My.Settings.InitialTheme.Equals(True) Then
Initial()
End If
and this is the Error thrown:
Code:
System.InvalidOperationException was unhandled
Message=Cross-thread operation not valid: Control 'Stopwatch' accessed from a thread other than the thread it was created on.
Source=System.Windows.Forms
StackTrace:
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.Control.Invalidate(Boolean invalidateChildren)
at DevComponents.DotNetBar.StyleManager.<>c__DisplayClass4.<OnColorTintChanged>b__1()
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DisplaySplash()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
-
Nov 16th, 2012, 12:35 PM
#10
Re: Help with Project (Saving and Updating)
I'm lost. Is MistyRose() a sub which applies the theme? If so where does it reside and how is it called in the actual program when (presumably) a user chooses it? Is the start up form part of the usual interface or does it just initialise some stuff and then pass control on to another form? Are you using the VB.Net stopwatch to do the grunt work (which would explain the cross threading problem)?
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Nov 16th, 2012, 02:40 PM
#11
Thread Starter
Member
Re: Help with Project (Saving and Updating)
Originally Posted by dunfiddlin
I'm lost. Is MistyRose() a sub which applies the theme? If so where does it reside and how is it called in the actual program when (presumably) a user chooses it? Is the start up form part of the usual interface or does it just initialise some stuff and then pass control on to another form? Are you using the VB.Net stopwatch to do the grunt work (which would explain the cross threading problem)?
Yes, MistyRose() is a sub which applies the theme. It resides in the Main Form which is also the Start-up form.
The user selects the Theme in the Settings form. Which calls the MistyRose() sub from the Main Form.
The Start-up form is the Main form, i.e: Contains the Stopwatch and Features.
Nope, I ain't using VB.Net Stopwatch.
The Stopwatch works solely based upon Timers.
In short... My app has only 2 forms. The Main form which contains the timers etc and the Settings Form
You can understand the Program much better if you download and install it..
https://sourceforge.net/projects/xtrmstpwtch/
-
Nov 16th, 2012, 02:54 PM
#12
Re: Help with Project (Saving and Updating)
The Stopwatch works solely based upon Timers.
Timer controls or system timers?
You can understand the Program much better if you download and install it..
Er yeah, I did that if you remember; it crashed. I've just downloaded and installed again. It crashed. So not much understanding gained there then!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Nov 16th, 2012, 03:13 PM
#13
Thread Starter
Member
Re: Help with Project (Saving and Updating)
Timer controls..
I can't understand why it crashes for you..
It works fine for me and on most of my friends' pc.
What Windows 7 are you running? 32 or 64 bit?
I am developing the app in Windows 7 64bit.
Do I have to change the Active Solution Patform to Any CPU ?
It is currently x86
<:> EDIT <:>
Alright.. I tried it on a Windows XP PC and it gave an error right after the splash screen.
After hours of searching and tweaking.. I think I got it working..
I'd appreciate if you could download and try it out. It should most probably work now..
Download link: https://sourceforge.net/projects/xtr...atest/download
Project Link: https://sourceforge.net/projects/xtrmstpwtch/
Please let me know how it goes..
Thanks alot for the help so far
Last edited by TheThinker; Nov 17th, 2012 at 08:19 AM.
-
Nov 22nd, 2012, 04:12 AM
#14
Thread Starter
Member
Re: Help with Project (Saving and Updating)
I've now tested it on both Windows 7 32/64 bit and Windows xp as well..
Its working.. no errors..
The problem is still the same:
Now... When the Theme is selected, then the form is closed..
Next time it opens up.. the Theme is still unchanged (default).... no changes.
But... when I open up the Settings Form the Theme that was last selected is applied.
-
Nov 25th, 2012, 07:27 AM
#15
Thread Starter
Member
Re: Help with Project (Saving and Updating)
How would I go about to appropriate call the Settings to be checked prior to loading the form without it giving me errors?
-
Nov 27th, 2012, 07:00 AM
#16
Thread Starter
Member
Re: Help with Project (Saving and Updating)
Switched to using the Stopwatch Class successfully.. Thanks to the Valuable Help from this Thread:
http://www.vbforums.com/showthread.p...59#post4288059
Now back to the Saving & Recalling the saved Theme
-
Nov 27th, 2012, 11:15 AM
#17
Thread Starter
Member
Re: Help with Project (Saving and Updating)
This is what I've got so far:
Settings Form:
Code:
Private Sub rbMistyRose_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbMistyRose.CheckedChanged
If rbMistyRose.Checked = True Then
StopwatchMain.MistyRose()
My.Settings.Save()
End If
End Sub
Code:
Private Sub Settings_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
My.Settings.Save()
End Sub
Main/Startup Form:
Code:
Private Sub StopwatchMain_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
If My.Settings.MistyRoseTheme.Equals(True) Then
'My.Settings.Reload()
MistyRose()
ElseIf My.Settings.InitialTheme.Equals(True) Then
Initial()
'My.Settings.Reload()
End If
End Sub
Last edited by TheThinker; Nov 27th, 2012 at 11:24 AM.
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
|