private void cbFontName_DrawItem(object sender, DrawItemEventArgs e) { // отображение заднего фона элемента e.DrawBackground(); // отображение значка и текста элемента FontListItem item = (FontListItem)cbFontName.Items[e.Index]; Font font = new Font(item.FontFamily, 14, FontStyle.Regular, GraphicsUnit.Pixel); e.Graphics.DrawString(item.ToString(), font, textBrush, e.Bounds.X + 2, e.Bounds.Y + 2); // отображение фокуса элемента e.DrawFocusRectangle(); }
private void SaveAndClose(object sender, RoutedEventArgs e) { FontListItem selectedFont = (FontListItem)list_fonts.SelectedItem; if (selectedFont == null) { selectedFont = fonts["Segoe UI"]; } Properties.Settings.Default.font_family = selectedFont.name; Properties.Settings.Default.font_size = Convert.ToInt32(slider_textsize.Value); Properties.Settings.Default.font_bold = (bool)check_bold.IsChecked; Properties.Settings.Default.font_shadow = (bool)check_shadow.IsChecked; var sep_item = (ListBoxItem)combo_separator.SelectedItem; var sep_string = (string)sep_item.Content; Properties.Settings.Default.clock_separator = sep_string[0]; Properties.Settings.Default.font_color = color[0].ToString() + "," + color[1].ToString() + "," + color[2].ToString(); Properties.Settings.Default.move_snap = (bool)check_movesnap.IsChecked; Properties.Settings.Default.window_pos = new System.Windows.Point(mainWin.Left, mainWin.Top); mainWin.LoadSettings(); Properties.Settings.Default.Save(); this.Close(); }
public SettingsBox(MainWindow win) { this.mainWin = win; InitializeComponent(); color = new int[3]; // list fonts fonts = new Dictionary <string, FontListItem>(); using (InstalledFontCollection fontsCollection = new InstalledFontCollection()) { FontFamily[] fontFamilies = fontsCollection.Families; int currentIndex = 0; foreach (FontFamily font in fontFamilies) { if (font.Name != string.Empty) { var fontListItem = new FontListItem(font.Name, font); fonts.Add(font.Name, fontListItem); list_fonts.Items.Add(fontListItem); if (font.Name == Properties.Settings.Default.font_family.Split(',')[0]) { list_fonts.SelectedIndex = currentIndex; } currentIndex++; } } } // load app settings list_fonts.SelectionMode = System.Windows.Controls.SelectionMode.Single; slider_textsize.Value = Properties.Settings.Default.font_size; l_textsizelabel.Content = "Size: " + Properties.Settings.Default.font_size.ToString(); check_bold.IsChecked = Properties.Settings.Default.font_bold; check_shadow.IsChecked = Properties.Settings.Default.font_shadow; check_movesnap.IsChecked = Properties.Settings.Default.move_snap; int i = 0; foreach (ListBoxItem item in combo_separator.Items) { if (((string)item.Content)[0] == Properties.Settings.Default.clock_separator) { combo_separator.SelectedIndex = i; } i++; } var color_str = Properties.Settings.Default.font_color.Split(','); for (int c = 0; c < 3; c++) { int.TryParse(color_str[c], out color[c]); } slider_red.Value = color[0]; slider_green.Value = color[1]; slider_blue.Value = color[2]; tx_red.Text = color[0].ToString(); tx_green.Text = color[1].ToString(); tx_blue.Text = color[2].ToString(); UpdateColorPreview(); slider_red.ValueChanged += UpdateColorBoxes; slider_green.ValueChanged += UpdateColorBoxes; slider_blue.ValueChanged += UpdateColorBoxes; tx_red.TextChanged += UpdateColorSliders; tx_green.TextChanged += UpdateColorSliders; tx_blue.TextChanged += UpdateColorSliders; slider_textsize.ValueChanged += UpdateTextSize; button_saveSettings.Click += SaveAndClose; }