gpt4 book ai didi

vb.net - 字体安装了吗?功能

转载 作者:行者123 更新时间:2023-12-02 07:03:28 25 4
gpt4 key购买 nike

我可以改进我的功能,不按每个元素进行搜索吗?

#Region " Font Is Installed? Function "

' [ Font Is Installed? Function ]
'
' Examples :
' MsgBox(Font_Is_Installed("Lucida Console"))

Private Function Font_Is_Installed(ByVal FontName As String) As Boolean
Dim AllFonts As New Drawing.Text.InstalledFontCollection
For Each Font As FontFamily In AllFonts.Families
If Font.Name.ToLower = FontName.ToLower Then Return True
Next
Return False
End Function

#End Region

UPDATE:

好吧,现在我看到了“.tolist”函数,现在我的代码是这样的:

Private Function Font_Is_Installed(ByVal FontName As String) As Boolean
Dim AllFonts As New Drawing.Text.InstalledFontCollection
Dim FontFamily As New FontFamily(FontName)
If AllFonts.Families.ToList().Contains(FontFamily) Then Return True Else Return False
End Function

我也有同样的问题:是最好用第二种方式改进,还是我可以改进得更好?

最佳答案

这里是

    Public Shared Function IsFontInstalled(ByVal FontName As String) As Boolean
Using TestFont As Font = New Font(FontName, 10)
Return CBool(String.Compare(FontName, TestFont.Name, StringComparison.InvariantCultureIgnoreCase) = 0)
End Using
End Function

关于vb.net - 字体安装了吗?功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15897941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com