How I can save the settings I want even after I close the program?
Let's say: If I have a Checkbox and I run the program. If I checked it I want to remain that way even when I reopen again the program. I hope you understand what I want.
I'm a newbie, so take me slow. Thank you.
I recommend using Application Settings Property Binding.
There are many options as mrunion mentioned in his good answer, but I think the most simple way in Windows Forms Application is using Application Settings Property Binding. To do so using designer:
Select your CheckBox in design surface
In properties window, at top, expand (ApplicationSettings), open dropdown for Checked property and select (New...) at bottom of dropdown.
Add your desired property with default value.
Save settings in somewhere like Form_Closing event:
C#: Properties.Settings.Default.Save();
VB: My.Settings.Save()
(ApplicationSettings) in property window:
Expanded from above....
To persist settings between different program runs, you will have to store that data somewhere for the user. Assuming since you mentioned VB, I will also assume Windows as your target platform. The best options are the following:
Use the registry to store the persistent data. There are plenty of tutorials on setting and retrieving registry variables.
Use a configuration/INI file for your application. Again, plenty of tutorials exist for this option.
Use a database. This is more advanced, but allows for the most flexibility of storing and retrieving data. I would suggest not using this method at first, and revisit it when you are ready to learn database design/querying/etc.
This should point you in the right direction.
Related
Hi there lovely StackOverFlow helpers, I got into a bit trouble recently.
I need to make an application in WinForm C# as my final programming project. The project is about managing Registry more nicely to make it easier for the user to edit values.
So what I need is; to show all the Registry values of the same type, to show what the value does and to show their build. For instance: the hierarchical build is HKEY_LOCAL_MACHINE\SYSTEM\Keyboard Layout\Preload and the key 1 controls the keyboard loadout when your pc first starts (about presenting it, I'll probably use RichTextBox for the graphical way or something else I'll figure out).
So I assume there's a way the data is placed in the Registry, like all of the setting of the app is here and the prefrences is there..
I hope I was clear enough, thanks for all of your time to read and answer it!! I really REALLY appreciate the effort!
I know its kind of stupid question, but I am beginner in C#.
I want to create start page with settings where user can set a values. How I can relay these values to other page ?
Solution that will give me someone will work with IsolatedStorage?
It does not have, but it's good to know for the future.
This question unfortunately needs a tutorial as answer. Bing has many of these:
Windows Phone 7 Jump Start Sessions (two funny guys show it all!!)
Quick Tutorial Page Navigation (involving a settings page!)
Tutorial Galore
Tips from Stackoverflow for getting started
Your task involves basic UI design, page navigation with parameters and/or data persistence.
And you are even allowed to use Google to find these.
If these settings need to be global, then add a static public member variable to the App.xaml.cs file. Set and Get as required from that property.
IsolatedStorage is useful for persisting data when your application closes, but otherwise in Memory persistence via globally accessible properties could be fine for your requirements.
This post is related to c# - approach for saving user settings in a WPF application?
I have found multiple examples for saving/loading one window configuration but I am not sure if it will also save the configurations for all usercontrols open inside that window or just the actual main windows configuration...
First is it possible to save/load multiple usercontrol configurations inside a window using the application/user settings?
Am I forced to just read/write xml to store the the multiple usercontrols configuration?
Thanks in advance and let me know if you need any other information!
EDIT
I have an application with a ribbonbar on top that allows the user to open one or more user controls from the ribbonbar. Hypothetically if i wanted to save all the open usercontrols window position, height, width, etc... would it still be possible to use the application settings to accomplish this?
EDIT2
I have an application and within that application there are many usercontrols a user can access. If a user opens 2 usercontrols and uses those controls often, I want to be able to save those usercontrols to the workspace so there always there when the program is open or closed. The way I am approaching it now is with serialized xml from the database. I was researching this topic and came across the application settings approach and wanted to know if this was a viable approach for my situation. Thanks again Marc for taking the time to help me figure this problem out.
What I've used is user-specific ApplicationSettings and binding those to properties I want to 'save'. Here's a good example of what I've done http://www.jaylee.org/post/2007/02/WPF-DataBinding-and-Application-Settings.aspx
I little more detail might be helpful here, I'm not sure I follow. Are you saying you have multiple instances of a given user control on a single window and you want to persist the properties for each of them?
A lot of this depends on how you created and populated those controls. If they were created dynamically from data for example, the best solution is to serialize that data to disk and re-create the controls when the application restarts.
Alternatively you could bake in the serialization of the settings into the user control itself such that it writes out it's settings to a file name based on it's instance name (control1.xml, control2.xml, etc) and then have it repopulate when the instance comes back to life.
Knowing how these controls are added and the properties are set in first place would be helpful.
Do you have any idea how to present all rows from let's say table with the possibility to click on particular row and open that way another window to edit?
I've got no idea how to create this. I would like to avoid access like creation by built-in wizards in Microsoft Visual Studio 2008.
Perhaps you know where I can find more information.
Execute a query which retrieves an overview of the records that you want to display.
When you double-click a row, you retrieve the records that represent that entity, and display it in another window...
That's in a nutshell how you could do it.
For a web application you may want to look at this Walkthrough as MSDN. You can find a winform walkthrough at MSDN as well. Though you say that you prefer doing it without the designers, I suggest that you go through the walkthrough using the designer and look at the code that it produces as a sample of how you could do it by hand. You could then adapt the example as needed for your purposes. For more references try googling "master detail view."
well i would use wpf with a stackpanel of listboxes
the rows are dynamically added to the stackpanel.
the listboxes contain textfields that are databind -ed to mouseclickevents and onchanged events.
http://dotnetslackers.com/articles/silverlight/WPFTutorial.aspx
I've been writing some small maintenance/viewer tools that each connect to a SQLServer (2005) database via System.Data.SqlClient classes.
(C# - .NET 3.5 - Windows.Forms)
For each of these tools I had to write the UI and dialog to let the user choose the right db and server: I connect to my test-db, my colleague uses my tools too and connects his test-db.
I'm looking for a plugable usercontrol that lets the user select a server, db and the rest of the connection parameters and that provides a SqlClient.SqlConnection to the rest of the application.
I've tried writing a usercontrol myself now, but I'm sure there must be others ,better ones and better tested ones. I've been Googling and looking at CodeProject, but found none.
There must be some better than one I wrote recently, because that one's so bad:
Just
Create a user control
drag a couple of buttons to it, anchor bottom center, make them ok and cancel
drag a Property Grid control onto it, dock fill
Add a read-only property to the control of type SqlConnectionStringBuilder, back it with a field
Initialize the field to a new SqlConnectionStringBuilder instance
In the Load event, set the Object property of the property grid to the SqlConnectionStringBuilder
That's pretty much that. The user just gets to fill in the properties. If you like, you can also create a ConnectionString property on the control and have it return the .ConnectionString property of the SqlConnectionStringBuilder.
What you're describing here is simple enough that I doubt there's something out there that does only this. You'd probably be better off sticking with your own code here.