Use the configuration file in winforms

Source: Internet
Author: User

During developmentProgramSuch as the file path and database link.

Use the following method in winform:

1. Create a configuration file:

In Solution Explorer, right-click the project name and choose add> new item> application configuration file;

The default name is app. config.

2. Modify the app. Con File

  1:   
      XML   version  =" 1.0"   encoding   =" UTF-8 "? > 
  2:     Configuration  > 
  3:     appsettings  > 
  4:     Add   key   =" username "  value   =" sa " />  
  5:     Add   key   =" PWD "  value   =" Sasa " />  
  6:     Add   key   =" servername "  value   =" Kay-PC " />  
  7:     Add   key   =" dbname "  value   =" pubs " />  
  8:     appsettings  > 
9: </Configuration>

 

The key is the name and the value is the key value.

3. Use the configuration file

For testing, put a button on the form to bring up the value of the key corresponding to the value.

1: // Add a namespace
 
2: UsingSystem. configuration;
  3:  ...... 
  4:   private   void  button2_click ( Object  sender, eventargs e) 
5:{
 
6:// Input the key name in the receivettings.
7:MessageBox. Show (configurationsettings. receivettings ["Username"]. Tostring ());
 
8:}

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.