简体   繁体   English

如何在C#中为带有.NET 2.0的Windows CE 5.0应用程序使用AddFontResource

[英]How to use AddFontResource in c# for Windows CE 5.0 application with .NET 2.0

I'm trying to develop a Smart Device program for Windows CE 5.0 device in my car with Visual Stdio 2008 pro and c# with .NET 2.0. 我正在尝试使用Visual Stdio 2008 pro和.NET 2.0的c#在我的车中为Windows CE 5.0设备开发智能设备程序。 I want to add a font using AddFontResourceEx, but I can't get it to work. 我想使用AddFontResourceEx添加字体,但无法使其正常工作。 Here is the code: 这是代码:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    private const uint FR_PRIVATE=0x10;
    [DllImport("GDI32.dll",EntryPoint="AddFontResourceEx")]
    static extern int AddFontResourceEx(string lpszFilename, uint fl, IntPtr pdv);

    private void button1_Click(object sender, EventArgs e)
    {
        AddFontResourceEx(".\\ELEPHNT.TTF", FR_PRIVATE, IntPtr.Zero);
       label1.ForeColor = Color.FromArgb(155, 25, 34);
       label1.Font = new Font("ELEPHNT.TTF", 18, FontStyle.Regular);
       label1.Text = "Hello world!";
    }
}

It builds succesfully and I can run the program, but the font won't change. 它可以成功构建,并且我可以运行该程序,但是字体不会改变。 I added the font file to the same directory where the program is. 我将字体文件添加到程序所在的目录中。 Could you please tell me what is wrong? 你能告诉我出什么事了吗?

您不能在C#代码中使用C ++声明,需要使用pinvoke和兼容的数据类型: http ://www.pinvoke.net/search.aspx?search=addfontresource&namespace=[All ]在Windows CE中没有相对的路径,因此您必须使用字体文件的完整路径,从开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM