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

家住魔仙堡 提交于 2019-12-14 03:04:42

问题


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?


回答1:


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 .



来源:https://stackoverflow.com/questions/48674694/how-to-use-addfontresource-in-c-sharp-for-windows-ce-5-0-application-with-net-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!