 |
|
VB.NET การใส่ Font file เข้าไปใน Resource แล้วจะเรียกใช้ยังไงครับ ? |
|
 |
|
|
 |
 |
|
คืออยากให้เอาโปรแกรมไปเปิดกับเครื่องอื่นที่ไม่มี Font นี้ ได้อ่ะคับ ลองหาโค้ดหรั่งดูแล้ว ได้มาแบบนี้ แต่มันใช้ไม่ได้ครับ
มีวิธีอื่นอีกไหมที่มันใช้ได้เหมือนกัน (ลองเขียนโค้ด Copy file font ลงใน C:\Windows\Fonts ก็ไม่ได้เหมือนกัน)
Code (VB.NET)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim mPFC As New PrivateFontCollection()
Dim mstrFont As String = "thaisanslite_r1.ttf"
Dim fontStream As System.IO.Stream = Me.GetType().Assembly.GetManifestResourceStream(mstrFont)
Dim Rawdata As System.IntPtr = Marshal.AllocCoTaskMem(fontStream.Length)
Dim fontData() As Byte
ReDim fontData(fontStream.Length)
fontStream.Read(fontData, 0, fontStream.Length)
Marshal.Copy(fontData, 0, Rawdata, fontStream.Length)
mPFC.AddMemoryFont(Rawdata, fontStream.Length)
fontStream.Close()
Marshal.FreeCoTaskMem(Rawdata)
Label1.Font = New Font("Thai Sans Lite", 12, FontStyle.Regular, GraphicsUnit.Point)
End Sub
Tag : .NET
|
|
 |
 |
 |
 |
Date :
2013-03-13 17:17:36 |
By :
supawat thonglamai |
View :
6934 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
add resource แล้วเรียกใช้ผ่าน global::[ชื่อโปรเจ็ค].properties.resource.[ชื่อ resource ที่ตั้งไว้]
|
 |
 |
 |
 |
Date :
2013-03-14 11:32:26 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จากที่คุณ TC Admin ให้มา ผมเอาไปดัดแปลงจนใช้ได้แล้วครับ ขอบคุณครับ
Code (VB.NET)
Private _pfc As New PrivateFontCollection
_pfc.AddFontFile(Application.StartupPath & "\thaisanslite_r1.ttf")
Label1.Font = New Font(_pfc.Families(0), 18, FontStyle.Regular)
|
 |
 |
 |
 |
Date :
2013-03-14 12:00:03 |
By :
supawat thonglamai |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จัดไป
|
 |
 |
 |
 |
Date :
2013-03-14 12:12:14 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|