在我的应用程序中,我想在运行时在一些文本框控件上设置 Consolas 字体。由于 Consolas 是 ClearType 字体,并且只有在启用 ClearType 时才看起来不错,所以我想检查是否启用了 ClearType。
我可以检查 ClearType 是否启用?
您可以使用FontSmoothingType属性System.Windows.Forms.SystemInformation
public static bool IsClearTypeEnabled
{
get
{
try
{
return SystemInformation.FontSmoothingType == 2;
}
catch //NotSupportedException
{
return false;
}
}
}
尝试使用SystemParametersInfo
,请参阅此链接了解更多信息:
和示例代码:
Private Declare Function SystemParametersInfo Lib "user32" Alias
"SystemParametersInfoA" (ByVal uAction As Integer, _
ByVal uParam As Integer, ByRef lpvParam As Integer, _
ByVal fuWinIni As Integer) As Boolean
Private Const SPI_GETFONTSMOOTHINGTYPE As Integer = &H200A
Private Const FE_FONTSMOOTHINGCLEARTYPE As Integer = 2
Private Function IsClearTypeEnabled() As Boolean
Dim uiType As Integer = 0
Return SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, uiType, 0)
AndAlso uiType = FE_FONTSMOOTHINGCLEARTYPE
End Function
除了@Claudio B 的回答之外,您可能还想检查该SystemInformation.IsFontSmoothingEnabled
属性,该属性检查是否启用了字体平滑。这是 ClearType 的独立设置:
public static bool IsClearTypeEnabled
{
get
{
return SystemInformation.IsFontSmoothingEnabled &&
SystemInformation.FontSmoothingType == 2;
}
, 是