private MConfig() { if (LoadConfig()) { return; } else { style = DEFAULT_STYLE; fsize = DEFAULT_FONTSIZE; columngap = DEFAULT_COLUMNGAP; } }
public bool LoadConfig() { try { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); KeyValueConfigurationCollection appsettings = config.AppSettings.Settings; KeyValueConfigurationElement kv = appsettings["Style"]; // if not defined "Style", set it to default if (null == kv || !Enum.TryParse(kv.Value, true, out style)) { style = DEFAULT_STYLE; } // if not defined "FontSize", set it to default kv = appsettings["FontSize"]; if (null == kv || !float.TryParse(kv.Value, out fsize)) { fsize = DEFAULT_FONTSIZE; } // if not defined "FontSize", set it to default kv = appsettings["ColumnGap"]; if (null == kv || !int.TryParse(kv.Value, out columngap)) { columngap = DEFAULT_COLUMNGAP; } } catch (Exception e) { Debug.WriteLine(e.ToString()); return(false); } return(true); }