For desktop applications Program You often need to record some user configuration information. The early practice is to read and write INI files.
For. NET applications that do not provide classes to directly operate INI files, you need to call WIN32API. For details, refer:
Http://www.blogcn.com/user52/seabluescn/blog/23969537.html It can be seen that this method is troublesome.
With the emergence of. Net framerwork 2.0, it provides internal support for application settings. Now, it is much easier to read and write configuration information.
1. Create a project and Open Properties \ Settings. settings. The name, type, and value of properties. You can understand it at a Glance. The only thing you need to talk about is the scope,
Application: program setting, read-only;
Uesr: User Configuration property: read/write.
We have created two configuration attributes: "connstr": string type, read-only, left: uint type, read/write.
:
2. Now you can use these two configuration attributes:
/// <Summary>
/// Read data
/// </Summary>
Private Void Btnread_click ( Object Sender, eventargs E)
{
String Connstr = Windowsapplication1.properties. settings. Default. connstr;
MessageBox. Show (connstr );
}
/// <Summary>
/// Store Data
/// </Summary>
Private Void Btnset_click ( Object Sender, eventargs E)
{
UintS= 123;
Windowsapplication1.properties. settings. Default. Left=S;
Windowsapplication1.properties. settings. Default. Save ();
}
3.The program directory contains a windowsapplication1.exe. config file, which can be directly modified to change the configuration.
4.for user configuration items (usermetadata, the modified value is not stored in the windowsapplication1.exe. config file, but stored in the C: \ Documents and settingsdirectory. The windowsapplication1.exe. config file retains the default value when the program fails to read the configuration. For the application configuration (application)(, the value is directly stored in the windowsapplication1.exe. config file (read-only ).
From: http://regulus.blog.hexun.com/18377750_d.html