在我的应用程序中,我想在运行时在某些文本框控件上设置Consolas字体。由于Consolas是ClearType字体,并且在启用ClearType时看起来很好,我想检查是否启用了ClearType。
我可以检查是否启用了ClearType?
答案 0 :(得分:1)
尝试使用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
答案 1 :(得分:1)
您可以使用System.Windows.Forms.SystemInformation
public static bool IsClearTypeEnabled
{
get
{
try
{
return SystemInformation.FontSmoothingType == 2;
}
catch //NotSupportedException
{
return false;
}
}
}
答案 2 :(得分:0)
除了@Claudio B的回答之外,您可能还需要检查SystemInformation.IsFontSmoothingEnabled
属性,该属性检查是否启用了字体平滑。这是ClearType的独立设置:
public static bool IsClearTypeEnabled
{
get
{
return SystemInformation.IsFontSmoothingEnabled &&
SystemInformation.FontSmoothingType == 2;
}
,y