Graphic code of the INI configuration file in C #

Source: Internet
Author: User
This article mainly for you in detail the C # operation INI configuration file example, with a certain reference value, interested in small partners can refer to

The example of this article for everyone to share the C # operation INI configuration file Examples of specific code for your reference, the specific content is as follows

Source file Address: C # operation INI configuration file example

The Created control:

Source:

Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.windows.forms;using system.runtime.interopservices;namespace    windowsformsapplication3{public partial class Form1:form {public Form1 () {InitializeComponent (); } [DllImport ("Kernel32.dll")] private static extern long WritePrivateProfileString (string section, string key, Stri     Ng value, string filepath); [DllImport ("Kernel32.dll")] private static extern int getprivateprofilestring (string section,string key,string def,str     Ingbuilder returnvalue,intbuffersize,string filepath);    private string IniFilePath;      private void Form1_Load (object sender, EventArgs e) {combobox1.text = "male";      for (int i = 1; i <=; i++) {ComboBox2.Items.Add (i.tostring ());      } combobox2.text = "18";    IniFilePath = Application.startuppath + "\\Config.ini"; } private void ButtOn1_click (object sender, EventArgs e) {if ((TextBox1.Text.Trim () = "") && (TextBox2.Text.Trim ()! = ""))        {string section = "Information";          try {writeprivateprofilestring (section, "Name", TextBox1.Text.Trim (), IniFilePath);          WritePrivateProfileString (section, "Gender", Combobox1.text, IniFilePath);          WritePrivateProfileString (section, "Age", Combobox2.text, IniFilePath);        WritePrivateProfileString (section, "Region", TextBox2.Text.Trim (), IniFilePath); } catch (Exception ee) {MessageBox.Show (EE.        Message); }} else {MessageBox.Show ("name or region cannot be empty!      "," Error ", MessageBoxButtons.OK, messageboxicon.warning);      }} private void Button2_Click (object sender, EventArgs e) {string outstring;        try {GetValue ("information", "Name", out outstring);        TextBox1.Text = outstring;  GetValue ("Information", "Gender", out outstring);      Combobox1.text = outstring;        GetValue ("Information", "age", out outstring);        Combobox2.text = outstring;        GetValue ("Information", "region", out outstring);      TextBox2.Text = outstring; } catch (Exception ee) {MessageBox.Show (EE.      Message);  }} private void GetValue (String section,string key, out string value) {StringBuilder StringBuilder = new      StringBuilder ();      GetPrivateProfileString (section, Key, "", StringBuilder, 1024x768, IniFilePath);    Value = Stringbuilder.tostring ();      } private void Button3_Click (object sender, EventArgs e) {TextBox1.Text = "";      Combobox1.text = "male";      Combobox2.text = "18";    TextBox2.Text = ""; }  }}

Operation Result:

Related Article

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.