如何在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

查看:177
本文介绍了如何在C#中为带有.NET 2.0的Windows CE 5.0应用程序使用AddFontResource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Visual Stdio 2008 pro和.NET 2.0的c#在汽车中为Windows CE 5.0设备开发智能设备程序。我想使用AddFontResourceEx添加字体,但无法使其正常工作。这是代码:

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. I want to add a font using AddFontResourceEx, but I can't get it to work. 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= [全部]
在Windows CE中没有相对路径,因此您必须使用字体文件的完整路径。 ,从。

You can't use a C++ declaration inside C# code, you need to use pinvoke and compatible data types: http://www.pinvoke.net/search.aspx?search=addfontresource&namespace=[All] In Windows CE there is no relative path, so you'll have to use the full path of your font file, starting from .

这篇关于如何在C#中为带有.NET 2.0的Windows CE 5.0应用程序使用AddFontResource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆