WPF Handwriting Code configuration file--Singleton

Source: Internet
Author: User
Tags read ini file

    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

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.