Public classSettinghelper {//WPF under Configuration file path Public Static ReadOnly stringSettingfilepath = AppDomain.CurrentDomain.BaseDirectory +"\\Setting.ini"; Private Static classInstance {Internal Static ReadOnlySettinghelper Setting =NewSettinghelper (); } PrivateSettinghelper () {} Public StaticSettinghelper getinstance () {returninstance.setting; } #regionAPI function Declaration[DllImport ("kernel32")]//returns 0 indicates failure, not 0 for success Private Static extern LongWritePrivateProfileString (stringSectionstringKeystringValstringFilePath); [DllImport ("kernel32")]//returns the length of the Get string buffer Private Static extern LongGetPrivateProfileString (stringSectionstringKeystringDef, StringBuilder RetVal,intSizestringFilePath); #endregion #regionRead INI file Public stringReadinidata (stringSectionstringkey) { returnReadinidata (section, Key,string. Empty); } Public stringReadinidata (stringSectionstringKeystringDefaultValue) { if(File.exists (Settingfilepath)) {StringBuilder s=NewStringBuilder (1024x768); GetPrivateProfileString (section, key, DefaultValue, S,1024x768, Settingfilepath); returns.tostring (); } Else { returnString.Empty; } } #endregion Public BOOLWriteinidata (stringSectionstringKeystringvalue) { if(File.exists (Settingfilepath)) {LongOpstation =writeprivateprofilestring (section, key, value, Settingfilepath); if(Opstation = =0) { return false; } Else { return true; } } Else { return false; } } Private stringwindowState; PublicWindowState WindowState {Get { if(string. Isnullorwhitespace (windowState)) {Settinghelper St=settinghelper.getinstance (); WindowState= St. Readinidata ("WPF","WindowState"); } if(string. Isnullorwhitespace (windowState)) {windowState= ((int) (System.Windows.WindowState.Normal). ToString (); } return(WindowState) Convert.ToInt32 (WindowState); } Set{windowState= ((int) value). ToString (); Settinghelper St=settinghelper.getinstance (); St. Writeinidata ("WPF","WindowState", windowState); } } Private stringLeft ; Public DoubleLeft {Get { if(string. Isnullorwhitespace (left)) {Settinghelper St=settinghelper.getinstance (); Left= St. Readinidata ("WPF"," Left"); } if(string. Isnullorwhitespace (left)} { Left=" -"; } returnconvert.todouble (left); } Set{ Left=value. ToString (); Settinghelper St=settinghelper.getinstance (); St. Writeinidata ("WPF"," Left", left); } } Private stringtop; Public DoubleTop {Get { if(string. Isnullorwhitespace (top)) {Settinghelper St=settinghelper.getinstance (); Top= St. Readinidata ("WPF","Top"); } if(string. Isnullorwhitespace (top) {top )=" -"; } returnconvert.todouble (top); } Set{Top=value. ToString (); Settinghelper St=settinghelper.getinstance (); St. Writeinidata ("WPF","Top", top); } } }
WPF Handwriting Code configuration file--Singleton