Automatically Configures the Class for Saving and Loading
This is a class helper that will make saving and loading settings easier. The class collects data from any given control, generates a key, type, and value, and saves it to a Json file. This is an example of the json file content after it has been saved.
The control names given to the designer by the user are the key names. The values and states are on the right.
This is the class identifier.
Then it’s really simple and straightforward to apply anyplace in the project. Form 1 is an example.
In the constructor, we first declare the class and create an instance.
Now we can save anything we want. For example, the value in a textbox controls changed events.
One single line for saving, no need to give names, no need to give any too many parameters.
Another example, this time, we are saving a checkbox control state:
Again, we are given a simple single line with the control name, and the class will do all the jobs for us.
The last thing is loading. We are going to load back everything to the controls, the values, and the states inside the form1 shown form.
We want to wait first for the form to be loaded and then load back the settings. And again, with one simple line.
It couldn’t be easier.
Two things to remember.
1. In the form1 constructor, when creating an instance for the class, enter your own path and file name where you want to save the settings file.
2. In the class itself in MySettings.cs I’m currently handling only textboxes and checkbox control types. But as you can see in the code, it’s very easy to add any other controls if you need them.
-
- Depending on your project and what controls you have in the form that you want to save information.
- In line 77 // Add more control types and properties as needed. Just add another one if you need any control. You need.
- In line 121 // Handle other control types as needed. Just follow the code above it and add any control handler.
- The reason that I didn’t add in both laces the code for all the existing controls is because it’s too much code, and it’s better that the user will add only the control he needs to use.
ASP.NET Core 8 Hosting Recommendation
HostForLIFE.eu
HostForLIFE.eu is a popular recommendation that offers various hosting choices. Starting from shared hosting to dedicated servers, you will find options fit for beginners and popular websites. It offers various hosting choices if you want to scale up. Also, you get flexible billing plans where you can choose to purchase a subscription even for one or six months.