Test if a Font is installed

前端 未结 7 1403
日久生厌
日久生厌 2020-11-30 08:34

Is there an easy way (in .Net) to test if a Font is installed on the current machine?

7条回答
  •  心在旅途
    2020-11-30 09:04

    string fontName = "Consolas";
    float fontSize = 12;
    
    using (Font fontTester = new Font( 
           fontName, 
           fontSize, 
           FontStyle.Regular, 
           GraphicsUnit.Pixel)) 
    {
        if (fontTester.Name == fontName)
        {
            // Font exists
        }
        else
        {
            // Font doesn't exist
        }
    }
    

提交回复
热议问题