Imports System.Drawing.Text Module Module2 '导入外部字体 Public Function ImportFont() As Font ' 获取字体文件的路径 Dim Path = Replace(Application.StartupPath, "\bin\Debug", "\res\segoeui.ttf") Try Dim NewFont1 As New PrivateFontCollection '建立一个 个人格式集合对象 NewFont1.AddFontFile(Path) '通过路径访问格式文件(这里的路径一定要对) 'New Font()里面可选多个参数,第一个参数就是格式名,第二个参数是字体大小,第三个参数是字体的粗细,正斜下划线等选项, '第四个参数是字体的度量单位,后面还有,不过是可选参数我直接默认了。读者可以自行试试 Dim NewFont As Font = New Font(NewFont1.Families(0).Name, 12, FontStyle.Regular, GraphicsUnit.Pixel) Return NewFont Catch ex As Exception Return Nothing End Try End Function End Module
'设置整个窗体中控件的字体 Private Sub SetControlFont() Dim Font1 As Font = ImportFont() '使用镶嵌循环语句,保证每个控件的字体都设置 If Font1 IsNot Nothing Then For Each Cotr As Control In Controls Cotr.Font = Font1 If Cotr.Controls IsNot Nothing Then For Each Cotr1 As Control In Cotr.Controls Cotr1.Font = Font1 Next End If Next End If End Sub好了,设置好了,只要在窗体的Load事件中调用SetControlFont()函数就可以设置该项目窗体上的每个控件的字体为Times New Roman
Private Sub frm_Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SetControlFont() End Sub
原文地址:http://blog.csdn.net/zhangyubishoulin/article/details/45035687