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