WinXP下系统使用的是楷体_GB2312而Win7下却只有楷体,没有楷体_GB2312。
现在我做的一个自定义控件需要用到楷体_GB2312并且一定要用这种字体,请问怎么解决?
说明下,不要让我用手工去下载安装字体,因为使用者不一定会安装字体甚至连下载都不会,谢谢!

解决方案 »

  1.   

    不可以改字体,因为楷体_GB2312与其他字体不同,楷体_GB2312在GDI+中可以分解成以笔画为单位的GraphicsPath,而其他的字体则不行
      

  2.   

    我测试过的,我上个星期一直在做这件事,我对我系统里的158种字体都测试了,只有楷体_GB2312跟DFKai-SB是有效的,但DFKai-SB在一些笔画上的绘制上是有问题的,所以我只能选用楷体_GB2312,绘制汉字笔画演示的代码我现在都写好了,就因为这个字体的局限性然后被老板说要解决了才能通过。
      

  3.   

    到最后还是要我自己结贴,通过一个朋友的帮忙踩解决这个问题,将资源内嵌到程序中,然后去获取这种字体即可,代码如下:
    private Font GetSpecialFont()
            {
                int size = 20;
                Font fnt = null;            if (null == m_pfc)
                {
                    string NameSpc = Assembly.GetExecutingAssembly().GetName().Name.ToString();
                    // First load the font as a memory stream
                    Stream stmFont = Assembly.GetExecutingAssembly().GetManifestResourceStream(
                                            NameSpc + ".标准楷体简.ttf");                if (null != stmFont)
                    {                    // 
                        // GDI+ wants a pointer to memory, GDI wants the memory.
                        // We will make them both happy.
                        //                    // First read the font into a buffer
                        byte[] rgbyt = new Byte[stmFont.Length];
                        stmFont.Read(rgbyt, 0, rgbyt.Length);                    // Then do the unmanaged font (Windows 2000 and later)
                        // The reason this works is that GDI+ will create a font object for
                        // controls like the RichTextBox and this call will make sure that GDI
                        // recognizes the font name, later.
                        //uint cFonts;
                        //AddFontMemResourceEx(rgbyt, rgbyt.Length, IntPtr.Zero, out cFonts);                    // Now do the managed font
                        IntPtr pbyt = Marshal.AllocCoTaskMem(rgbyt.Length);
                        if (null != pbyt)
                        {
                            Marshal.Copy(rgbyt, 0, pbyt, rgbyt.Length);
                            m_pfc = new PrivateFontCollection();
                            m_pfc.AddMemoryFont(pbyt, rgbyt.Length);
                            Marshal.FreeCoTaskMem(pbyt);
                        }
                    }
                }            if (m_pfc.Families.Length > 0)
                {
                    // Handy how one of the Font constructors takes a
                    // FontFamily object, huh? :-)
                    fnt = new Font(m_pfc.Families[0], size);
                }            return fnt;
            }