How to configure settings. Settings Using the application in DOTNET 2.0

Source: Internet
Author: User
Tags dotnet
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.