c#在wince中,在picturebox上画文字,因为GDI+不能实现字体倾斜等效果,所以调用API的CreateFontIndirect实现,程序如下,但是编译后在Font myFont = Font.FromHfont(A);这行提示“值不在预期范围”,纠结很久了,不知什么原因?using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;    //使用外部Win32 APInamespace DeviceApplication3
{
    public partial class Form1 : Form
    {
        //[DllImport("gdi32", EntryPoint = "CreateFont")]                   //windows下的库
        [DllImport("coredll.dll", EntryPoint = "CreateFontIndirect")]       //wince下的库
        public static extern IntPtr CreateFontIndirect(
        int nHeight,                //字符逻辑高度
        int nWidth,                 //逻辑单位指定字体字符的平均宽度
        int nEscapement,            //以十分之一度为单位指定每一行文本输出时相对于页面底端的角度
        int nOrientation,           //以十分之一度为单位指定字符基线相对于页面底端的角度
        int fnWeight,               //字体重量,0~1000,正常为400,粗体为700。0则为默认的字体重量
        uint fdwItalic,             //lfItalic为TRUE时使用斜体
        uint fdwUnderline,          //lfUnderline为TRUE时给字体添加下划线
        uint fdwStrikeOut,          //当lfStrikeOut为TRUE时给字体添加删除线
        uint fdwCharSet,            //指定字符集。可以使用下面的预定义值:ANSI_CHARSET、OEM_CHARSET、SYMBOL_CHARSET、UNICODE_CHARSET,其中OEM字符集是与操作系统相关的
        uint fdwOutputPrecision,    //指定输出精度,OUT_CHARACTER_PRECIS、OUT_DEFAULT_PRECIS、OUT_STRING_PRECIS、OUT_STROKE_PRECIS
        uint fdwClipPrecision,      //剪辑精度。定义当字符超过剪辑区时对字符的剪辑方式,CLIP_CHARACTER_PRECIS、CLIP_DEFAULT_PRECIS、CLIP_STROKE_PRECIS
        uint fdwQuality,            //输出质量。定义图形设备接口在匹配逻辑字体属性到实际的物理字体的使用的方式,DEFAULT_QUALITY (默认质量)、DRAFT_QUALITY (草稿质量)、PROOF_QUALITY (正稿质量)
        uint fdwPitchAndFamily,     //字体的字符间距和族
        string lpszFace);           //字体名        const int ANSI_CHARSET = 0;
        const int GB2312_CHARSET = 134;
        const int OUT_DEFAULT_PRECIS = 0;
        const int CLIP_DEFAULT_PRECIS = 0;
        const int DEFAULT_QUALITY = 0;
        const int DEFAULT_PITCH = 0;        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            Bitmap img = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics g = Graphics.FromImage(img);
            g.Clear(Color.Blue);
            IntPtr A = CreateFontIndirect(
            0,                          //字符逻辑高度,默认
            0,                          //
            0,
            0,
            100,                        //粗细100
            0,
            0,
            0,
            ANSI_CHARSET,               //字符集,ANSI_CHARSET
            OUT_DEFAULT_PRECIS,
            CLIP_DEFAULT_PRECIS,
            DEFAULT_QUALITY,
            DEFAULT_PITCH,
            "宋体");
            Font myFont = Font.FromHfont(A);
            g.DrawString("Look", myFont, new SolidBrush(Color.Black), 0, 0);
            pictureBox1.Image = img;
            myFont.Dispose();
            g.Dispose();
        }
    }
}
APICreateFontIndirectFont字体C#