C # by generating the INI file, remembering the user's choice before closing the program + ignoring cross-thread checking

Source: Internet
Author: User

1. Add the inside of the class

Write config file
[DllImport ("kernel32")]
private static extern long writeprivateprofilestring(string section, string key, String val, string filePath);// System DLL Import INI write function
[DllImport ("kernel32")]
private static extern int getprivateprofilestring(string section, String key, String Def, StringBuilder RetVal, I NT size, string filePath);//System DLL Import INI read function
string filename = System.AppDomain.CurrentDomain.BaseDirectory + "Data.ini";//ini file name
StringBuilder temp = new StringBuilder(255);//store read INI content variable

2. Save the data before the interface is closed

private void form_jmt_isp_formclosing(object sender, FormClosingEventArgs e)
{
  writeprivateprofilestring ("InitData", "Mcu_sort", Combobox_jmtsort_select. Text, FileName);//window close, save

That partition--variable name----variable Value--------------------------file path

}

3. Read data when the interface starts again

private void form_jmt_isp_load(object sender, EventArgs e)
{

  getprivateprofilestring ("InitData", "Mcu_sort", "JMT 1801 series", Temp, n, FileName);//window close, save

That partition--variable name-- if no variable default value----Read value-size-File path
  Combobox_jmtsort_select. Text = temp. ToString ();

System.Windows.Forms.Control. Checkforillegalcrossthreadcalls = false; Ignore cross-thread checking

}

C # by generating the INI file, remembering the user's choice before closing the program + ignoring cross-thread checking

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.