protected override void OnLoad(EventArgs e) { //build list of OpenType fonts var lf = new Logfont(); var plogFont = Marshal.AllocHGlobal(Marshal.SizeOf(lf)); Marshal.StructureToPtr(lf, plogFont, true); try { _fontList.Clear(); using (var g = CreateGraphics()) { var p = g.GetHdc(); EnumFontFamiliesEx(p, plogFont, Callback, IntPtr.Zero, 0); g.ReleaseHdc(p); } } finally { Marshal.DestroyStructure(plogFont, typeof(Logfont)); } //sort fonts _fontList.Sort((f1, f2) => f1.elfFullName.CompareTo(f2.elfFullName)); //build combobox cbFont.Items.Clear(); foreach (var item in _fontList) { cbFont.Items.Add(item); } }
protected override void OnLoad(EventArgs e) { //build list of OpenType fonts var lf = new Logfont(); var plogFont = Marshal.AllocHGlobal(Marshal.SizeOf(lf)); Marshal.StructureToPtr(lf, plogFont, true); try { _fontList.Clear(); using (var g = CreateGraphics()) { var p = g.GetHdc(); EnumFontFamiliesEx(p, plogFont, Callback, IntPtr.Zero, 0); g.ReleaseHdc(p); } } finally { Marshal.DestroyStructure(plogFont, typeof (Logfont)); } //sort fonts _fontList.Sort((f1, f2) => f1.elfFullName.CompareTo(f2.elfFullName)); //build combobox cbFont.Items.Clear(); foreach (var item in _fontList) cbFont.Items.Add(item); }
public OpenTypeFontStyle(FastColoredTextBox fctb, Logfont font) : base(null, null, FontStyle.Regular) { _font = font; //measure font using (var gr = fctb.CreateGraphics()) { var hdc = gr.GetHdc(); var fontHandle = CreateFontIndirect(font); var f = SelectObject(hdc, fontHandle); var measureSize = new Size(0, 0); try { GetTextExtentPoint(hdc, "M", 1, ref measureSize); } finally { DeleteObject(SelectObject(hdc, f)); gr.ReleaseHdc(hdc); } fctb.CharWidth = measureSize.Width; fctb.CharHeight = measureSize.Height + fctb.LineInterval; fctb.NeedRecalc(true, true); } }
public static extern IntPtr CreateFontIndirect([In, MarshalAs(UnmanagedType.LPStruct)] Logfont lplf);