Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if ClearType is enabled in Windows

Tags:

c#

.net

vb.net

In my application I want to set the Consolas font on some textbox controls at runtime. As Consolas is a ClearType font and only does look good when ClearType is enabled, I want to check if ClearType is enabled.

Can I check if ClearType is enabled?


2 Answers

you can use the FontSmoothingType property of System.Windows.Forms.SystemInformation

public static bool IsClearTypeEnabled
{
    get
    {
        try
        {
            return SystemInformation.FontSmoothingType == 2;
        }
        catch //NotSupportedException
        {
            return false;
        }
    }
}
like image 184
Claudio B Avatar answered Sep 20 '25 09:09

Claudio B


Try to use SystemParametersInfo, see this link for more info:

  • ClearType Antialiasing from MSDN

and a sample code:

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
like image 30
Ria Avatar answered Sep 20 '25 07:09

Ria