private void ComboFont_DrawItem(object sender, DrawItemEventArgs e) { try { FontComboItem item = ComboFont.Items[e.Index] as FontComboItem; if (item == null) { return; } e.DrawBackground(); e.Graphics.DrawString(item.Font.Name, new Font(item.Font.FontFamily.Name, this.Font.Size), new SolidBrush(e.ForeColor), e.Bounds, StringFormat.GenericDefault); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void ComboFont_MeasureItem(object sender, MeasureItemEventArgs e) { try { FontComboItem item = ComboFont.Items[e.Index] as FontComboItem; if (item == null) { return; } Size size = e.Graphics.MeasureString(item.Font.FontFamily.Name, item.Font).ToSize(); e.ItemHeight = ComboFont.ItemHeight; e.ItemWidth = size.Width; ComboFont.DropDownWidth = Math.Max(ComboFont.DropDownWidth, size.Width); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void LoadFont() { FontComboItem item; FontCollection fontCollection = new InstalledFontCollection(); ComboFont.Items.Clear(); ComboFont.BeginUpdate(); for (int i = 0; i < fontCollection.Families.Length; i++) { if (!fontCollection.Families[i].IsStyleAvailable(FontStyle.Regular)) { continue; } item = new FontComboItem(fontCollection.Families[i].Name); ComboFont.Items.Add(item); } ComboFont.EndUpdate(); ComboFont.Text = this.Font.FontFamily.Name; }