none
TTF use from Application Resources Folder RRS feed

  • Question

  • TTF file use from resources folder

    I have applied this

     Dim bytes() As Byte = My.Resources.simfang
     Dim pResource As IntPtr = Marshal.AllocCoTaskMem(bytes.Length)
     Marshal.Copy(bytes, 0, pResource, bytes.Length)
     Dim nNumFonts As Integer = 0
     AddFontMemResourceEx(pResource, bytes.Length, IntPtr.Zero, nNumFonts)

    Dim font As BaseFont = BaseFont.CreateFont(AppDomain.CurrentDomain.BaseDirectory + "../../Resources/SIMFANG.TTF")

    Best Regards

    Wednesday, August 14, 2019 10:09 AM

Answers

  • Hi,

    What problem have you encountered? To use the ".ttf" to set control's font, you can refer to this code.

        Dim path As String = AppDomain.CurrentDomain.BaseDirectory & "../../Resources/test.ttf"
        Dim pfc As PrivateFontCollection = New PrivateFontCollection()
        pfc.AddFontFile(path)
        Dim f As System.Drawing.Font = New System.Drawing.Font(pfc.Families(0), 16)
        RichTextBox1.Font = f

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by CompuTechSide Thursday, August 15, 2019 5:38 PM
    Thursday, August 15, 2019 1:48 AM
    Moderator
  • Hi,

    Modify it like this,

        Dim font As BaseFont = BaseFont.CreateFont(AppDomain.CurrentDomain.BaseDirectory & "../../Resources/test.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by CompuTechSide Thursday, August 15, 2019 5:38 PM
    Thursday, August 15, 2019 8:37 AM
    Moderator

All replies

  • Hi,

    What problem have you encountered? To use the ".ttf" to set control's font, you can refer to this code.

        Dim path As String = AppDomain.CurrentDomain.BaseDirectory & "../../Resources/test.ttf"
        Dim pfc As PrivateFontCollection = New PrivateFontCollection()
        pfc.AddFontFile(path)
        Dim f As System.Drawing.Font = New System.Drawing.Font(pfc.Families(0), 16)
        RichTextBox1.Font = f

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by CompuTechSide Thursday, August 15, 2019 5:38 PM
    Thursday, August 15, 2019 1:48 AM
    Moderator
  • Hi,

    Its ok fine but how to add here under below line ("C:\WINDOWS\Fonts\SIMFANG.TTF")  refer Above code.

    Dim font As BaseFont = BaseFont.CreateFont("C:\WINDOWS\Fonts\SIMFANG.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)

    Best Regards

    Thursday, August 15, 2019 8:24 AM
  • Hi,

    Modify it like this,

        Dim font As BaseFont = BaseFont.CreateFont(AppDomain.CurrentDomain.BaseDirectory & "../../Resources/test.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by CompuTechSide Thursday, August 15, 2019 5:38 PM
    Thursday, August 15, 2019 8:37 AM
    Moderator