In a desktop application needing some serious re-factoring, I have several chunks of code that look like this:
private void LoadSettings()
{
WindowState = Properties.Settings.Default.WindowState;
Location = Properties.Settings.Default.WindowLocation;
...
}
private void SaveSettings()
{
Properties.Settings.Default.WindowState = WindowState;
Properties.Settings.Default.WindowLocation = Location;
...
}
What's the best way to replace this? Project-imposed constraints:
Update
For posterity, I've also found two useful tutorials: "Windows Forms User Settings in C#" and "Exploring Secrets of Persistent Application Settings".
I've asked a follow-up question about using this technique to bind a form's Size here. I separated them out to help people who search for similar issues.
A simple way is to use a configuration data object, save it as an XML file with the name of the application in the local Folder and on startup read it back.
Solution 1. Create a Static class that holds the User name and password and any other variables need in entire application. Now you can access the UserID from anywhere in your code, or set a value from any where.
If you open your windows form in the designer, look in the properties box. The first item should be "(ApplicationSetting)". Under that is "(PropertyBinding)". That's where you'll find the option to do exactly what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With