Test if a Font is installed

前端 未结 7 1402
日久生厌
日久生厌 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:18

    Thanks to Jeff, I have better read the documentation of the Font class:

    If the familyName parameter specifies a font that is not installed on the machine running the application or is not supported, Microsoft Sans Serif will be substituted.

    The result of this knowledge:

        private bool IsFontInstalled(string fontName) {
            using (var testFont = new Font(fontName, 8)) {
                return 0 == string.Compare(
                  fontName,
                  testFont.Name,
                  StringComparison.InvariantCultureIgnoreCase);
            }
        }
    

提交回复
热议问题