繁体   English   中英

在资源中保存自定义字体VISUAL BASIC

[英]Saving custom font in resources VISUAL BASIC

我将下载的字体保存在资源中,并希望在加载程序时在某些复选框上进行设置。

我已经尝试过了:

Checkbox1.Font = My.Resources.Allstar

(“ Allstar”是c的字体名称)

但这给了我一个错误:

类型“字节的一维数组”的值不能转换为“ System.Drawing.Font”

将资源加载到PrivateFontCollection对象中。 这样的事情应该很接近:

    Dim lstPrivateFontCollection As New System.Drawing.Text.PrivateFontCollection

    Dim objPointer As IntPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(My.Resources.Allstar.length)

    System.Runtime.InteropServices.Marshal.Copy(My.Resources.Allstar, 0, objPointer, My.Resources.Allstar.Length)

    lstPrivateFontCollection.AddMemoryFont(objPointer, My.Resources.Allstar.Length)

    'Omit next line due to instability pointed out in comments by Hans Passant.
    'It was used to free memory, but could cause app to crash.
    'System.Runtime.InteropServices.Marshal.FreeCoTaskMem(objPointer)

    Dim objFont As New System.Drawing.Font(lstPrivateFontCollection.Families(0), 16.0F, System.Drawing.FontStyle.Regular, GraphicsUnit.Point)

    lstPrivateFontCollection.Dispose()

    Checkbox1.Font = objFont

暂无
暂无

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

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