コード例 #1
0
        protected override void OnLoad(EventArgs e)
        {
            //build list of OpenType fonts
            LOGFONT lf = new LOGFONT();

            IntPtr plogFont = Marshal.AllocHGlobal(Marshal.SizeOf(lf));

            Marshal.StructureToPtr(lf, plogFont, true);

            try
            {
                fontList.Clear();
                using (Graphics G = CreateGraphics())
                {
                    IntPtr 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);
            }
        }
コード例 #2
0
        public OpenTypeFontStyle(FastColoredTextBox fctb, LOGFONT font) : base(null, null, FontStyle.Regular)
        {
            this.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);
            }
        }
コード例 #3
0
 public static extern IntPtr CreateFontIndirect([In, MarshalAs(UnmanagedType.LPStruct)] LOGFONT lplf);