The role of setting.settings in WinForm in the development of VS C #

Source: Internet
Author: User

1, define the configuration fields in the Settings.settings file. The scope is defined as: User can be changed while running, Applicatiion is not changed when run. Can use the data grid view, very convenient;2, read configuration value Text1.Text=Properties.Settings.Default.FieldName;//FieldName is the field you define3, modify, and save the configuration Properties.Settings.Default.FieldName="Server"; Properties.Settings.Default.Save ();//save changes using the Save method4, or you can create a configuration class ftpsetting yourself. In the WinForm application, all configuration classes inherit from the ApplicationSettingsBase class. Sealed classFtpsettings:applicationsettingsbase{[userscopedsetting][defaultsettingvalue ("127.0.0.1")] Public stringserver{Get{return(string) This["Server"]; }Set{ This["Server"] =value;}} [Userscopedsetting] [Defaultsettingvalue (" +")] Public intport{Get{return(int) This["Port"]; }Set{ This["Port"] =value;}}} Using the above configuration class, you can use:Private voidButton2_Click (Objectsender, EventArgs e) {ftpsettings FTP=Newftpsettings ();stringmsg = Ftp.server +":"+ftp.Port.ToString (); MessageBox.Show (msg);} When we use the above ftpsetting configuration, of course, we must first make the assignment to save, then use, then modify, then save, and then use. Private voidButton2_Click (Objectsender, EventArgs e) {ftpsettings FTP=Newftpsettings (); Ftp.server="ftp.test.com"; Ftp.port=8021; Ftp.save (); Ftp.reload ();stringmsg = Ftp.server +":"+ftp.Port.ToString (); MessageBox.Show (msg);} Well. Already saved, you may not be able to find where it is in the application folder. Since we are using Userscope, the configuration information is actually saved to your Windows personal folder. For example mine is C:\Documents and Settings\brooks\local Settings\Application Data\testwinform directory. 

The role of setting.settings in WinForm in the development of VS C #

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.