• 쇼핑몰
  • 커뮤니티
  • 북마크

vb.net




[File] [vb.net] 경로 또는 리소스(Resources) ttf 파일 폰트 변환

하나를하더라도최선을
2019.08.04 18:45 916 0

본문



경로:)

  Dim privateFonts As New System.Drawing.Text.PrivateFontCollection()

  privateFonts.AddFontFile("C:\Program Files (x86)\Hnc\Office 2018\HOffice100\Shared\TTF\Hwp\Easop.ttf")

  Dim fam As FontFamily = privateFonts.Families(0)

  Dim font As New System.Drawing.Font(fam, 12)

Resources:)

  Dim myFonts As PrivateFontCollection

  Dim fontBuffer As IntPtr

  myFonts = New PrivateFontCollection()

  Dim font As Byte() = My.Resources.HYBSRB '// Easop

  fontBuffer = Marshal.AllocCoTaskMem(font.Length)

  Marshal.Copy(font, 0, fontBuffer, font.Length)

  myFonts.AddMemoryFont(fontBuffer, font.Length)

  Dim fam As FontFamily = myFonts.Families(0)

  Dim fnt As Font = New Font(fam, 16)

예제:)
 

Imports System.Drawing.Text
Imports System.Runtime.InteropServices
 
Public Partial Class Form1
    Inherits Form
 
    Private Shared myFonts As PrivateFontCollection
    Private Shared fontBuffer As IntPtr
 
 
            myFonts = New PrivateFontCollection()
            Dim font As Byte() = Properties.Resources.test
            fontBuffer = Marshal.AllocCoTaskMem(font.Length)
            Marshal.Copy(font, 0, fontBuffer, font.Length)
            myFonts.AddMemoryFont(fontBuffer, font.Length)
 
 
    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Dim fam As FontFamily = myFonts.Families(0)
    dim fnt As Font = New Font(fam, 16)
        Using fnt As Font = New Font(fam, 16)
            TextRenderer.DrawText(e.Graphics, "Private font", fnt, Point.Empty, Color.Black)
        End Using
    End Sub
End Class



댓글목록 0

등록된 댓글이 없습니다.