/// <summary> /// Сохранение параметров в реестре /// </summary> /// <param name="paramInfo">Структура, содержащая все сохраняемые параметры</param> public void SaveParameter(ParametersInfo paramInfo) { if (!_useRegister) { return; } RegistryKey regKey = Registry.CurrentUser; regKey = regKey.CreateSubKey(RegPath); // Сохранение размера и позиции формы if (regKey != null) { regKey.SetValue("MfWindState", paramInfo.MfWindState.ToString()); if (paramInfo.MfLocation.X >= 0 && paramInfo.MfLocation.Y >= 0) { regKey.SetValue("MfSize", paramInfo.MfSize.Width + ";" + paramInfo.MfSize.Height); regKey.SetValue("MfLocation", paramInfo.MfLocation.X + ";" + paramInfo.MfLocation.Y); } // Сохранение опций regKey.SetValue("WordWrap", paramInfo.WordWrap.ToString()); regKey.SetValue("HistoryWrite", paramInfo.HistoryWrite.ToString()); regKey.SetValue("language", paramInfo.KeyboardLayoutId.ToString()); // Сохранение шрифтов regKey.SetValue("fontSize", paramInfo.TextFont.Size.ToString()); regKey.SetValue("fontName", paramInfo.TextFont.Name); regKey.SetValue("fontBold", paramInfo.TextFont.Bold.ToString()); regKey.SetValue("fontItalic", paramInfo.TextFont.Italic.ToString()); regKey.SetValue("fontUnderline", paramInfo.TextFont.Underline.ToString()); regKey.SetValue("fontStrikeout", paramInfo.TextFont.Strikeout.ToString()); regKey.SetValue("foreColor", paramInfo.TextForeColor.Name); } }
/// <summary> /// Загрузка параметров из реестра /// </summary> /// <returns>Структура, содержащая все загруженные параметры</returns> public void LoadParameter(out ParametersInfo paramInfo) { paramInfo = new ParametersInfo { MfWindState = FormWindowState.Normal, MfSize = new Size(250, 250), MfLocation = new Point(150, 150), WordWrap = false, HistoryWrite = true, KeyboardLayoutId = 1049, TextFont = new Font("Microsoft Sans Serif", (float)8.25), TextForeColor = Color.Black }; if (!_useRegister) { return; } RegistryKey regKey; // Чтение значений из реестра string s = ""; try { regKey = Registry.CurrentUser; regKey = regKey.CreateSubKey(RegPath); // ReSharper disable PossibleNullReferenceException s = (string)regKey.GetValue("MfWindState", s); // ReSharper restore PossibleNullReferenceException } catch { _useRegister = false; return; } if (s == "Maximized") { paramInfo.MfWindState = FormWindowState.Maximized; } else if (s == "Minimized") { paramInfo.MfWindState = FormWindowState.Minimized; } try { s = ""; s = (string)regKey.GetValue("MfSize", s); string[] arr = s.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries); if (arr.Length == 2) { paramInfo.MfSize = new Size(Convert.ToInt32(arr[0]), Convert.ToInt32(arr[1])); } s = ""; s = (string)regKey.GetValue("MfLocation", s); arr = s.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries); if (arr.Length == 2 && Convert.ToInt32(arr[0]) > 0 && Convert.ToInt32(arr[1]) > 0) { paramInfo.MfLocation = new Point(Convert.ToInt32(arr[0]), Convert.ToInt32(arr[1])); } s = ""; s = (string)regKey.GetValue("WordWrap", s); if (s != "") { paramInfo.WordWrap = Convert.ToBoolean(s); } s = ""; s = (string)regKey.GetValue("HistoryWrite", s); if (s != "") { paramInfo.HistoryWrite = Convert.ToBoolean(s); } s = ""; s = (string)regKey.GetValue("language", s); if (s != "") { paramInfo.KeyboardLayoutId = Convert.ToInt32(s); } // Загрузка данных о шрифтах float fontSize = paramInfo.TextFont.Size; s = ""; s = (string)regKey.GetValue("fontSize", s); if (s != "") { fontSize = (float)Convert.ToDouble(s); } string fontName = paramInfo.TextFont.Name; s = ""; s = (string)regKey.GetValue("fontName", s); if (s != "") { fontName = s; } bool fontBold = paramInfo.TextFont.Bold; s = ""; s = (string)regKey.GetValue("fontBold", s); if (s != "") { fontBold = Convert.ToBoolean(s); } bool fontItalic = paramInfo.TextFont.Italic; s = ""; s = (string)regKey.GetValue("fontItalic", s); if (s != "") { fontItalic = Convert.ToBoolean(s); } bool fontUnderline = paramInfo.TextFont.Underline; s = ""; s = (string)regKey.GetValue("fontUnderline", s); if (s != "") { fontUnderline = Convert.ToBoolean(s); } bool fontStrikeout = paramInfo.TextFont.Strikeout; s = ""; s = (string)regKey.GetValue("fontStrikeout", s); if (s != "") { fontStrikeout = Convert.ToBoolean(s); } FontStyle fs = FontStyle.Regular; if (fontBold) { fs = fs | FontStyle.Bold; } if (fontItalic) { fs = fs | FontStyle.Italic; } if (fontUnderline) { fs = fs | FontStyle.Underline; } if (fontStrikeout) { fs = fs | FontStyle.Strikeout; } paramInfo.TextFont = new Font(fontName, fontSize, fs); s = ""; s = (string)regKey.GetValue("foreColor", s); if (s != "") { paramInfo.TextForeColor = Color.FromName(s); } } // ReSharper disable EmptyGeneralCatchClause catch { } // ReSharper restore EmptyGeneralCatchClause }