private void UpdateFontStyle() { chkStrikeout.Checked = (selectedFont.Style & FontStyle.Strikeout) == FontStyle.Strikeout; chkUnderline.Checked = (selectedFont.Style & FontStyle.Underline) == FontStyle.Underline; styleList.Items.Clear(); if (string.IsNullOrEmpty(selectedFont.Name)) { styleList.Enabled = false; } else { styleList.Enabled = true; using (FontFamily ff = new FontFamily(selectedFont.Name)) { if (ff.IsStyleAvailable(FontStyle.Regular)) { styleList.Items.Add("Regular"); } if (ff.IsStyleAvailable(FontStyle.Italic)) { styleList.Items.Add("Italic"); } if (ff.IsStyleAvailable(FontStyle.Bold)) { styleList.Items.Add("Bold"); } if (ff.IsStyleAvailable(FontStyle.Bold | FontStyle.Italic)) { styleList.Items.Add("Bold Italic"); } chkStrikeout.Enabled = ff.IsStyleAvailable(FontStyle.Strikeout); if (!chkStrikeout.Enabled) { chkStrikeout.Checked = false; } chkUnderline.Enabled = ff.IsStyleAvailable(FontStyle.Underline); if (!chkUnderline.Enabled) { chkUnderline.Checked = false; } int foundOldStyle = -1; for (int i = 0; i < styleList.Items.Count; i++) { string text = Convert.ToString(styleList.Items[i]); FontStyle fs = FontUIToolkit.GetFontStyleByName(text, "italic", "bold"); if (fs == SelectedFont.Style) { styleList.SelectedIndex = foundOldStyle = i; break; } } if (foundOldStyle == -1 && styleList.Items.Count > 0) { styleList.SelectedIndex = 0; selectedFont.Style = FontUIToolkit.GetFontStyleByName(Convert.ToString(styleList.Items[0]), "italic", "bold"); if (chkUnderline.Checked) { selectedFont.Style |= FontStyle.Underline; } if (chkStrikeout.Checked) { selectedFont.Style |= FontStyle.Strikeout; } } } } txtStyle.Text = FontUIToolkit.GetFontStyleName(selectedFont.Style, "Regular", "Italic", "Bold"); labSample.Invalidate(); }
private void SetFontStyleByStyle(FontStyle style) { txtStyle.Text = FontUIToolkit.GetFontStyleName(style, "Regular", "Italic", "Bold"); }