如何在 VS 扩展中检索文本编辑器的字体大小?

How do you retrieve the font size of the text editor in a VS extension?

您可以通过以下方式找到字体大小:

工具>选项>环境>字体和颜色>文本编辑器>纯文本

但是,如果您想在 VS 扩展 (vsix) 中执行此操作,您可以执行以下操作:

DTE vsEnvironment = (DTE)GetService(typeof(SDTE));
EnvDTE.Properties propertiesList = vsEnvironment.get_Properties("Environment", "FontsAndColors");
Property prop = propertiesList.Item("TextEditor");
short size = (short)prop.Value;

遗憾的是,我似乎无法找到检索所需 propertyList 的神奇秘诀。 “FontsAndColors”和所有合理的排列都失败了。

问题: 有没有方法可以检索现有的密钥。或者更好的是,如何在 VS 扩展中检索文本编辑器的字体大小?

您可以使用以下代码获取文本编辑器的字体大小:

    EnvDTE.Properties propertiesList = vsEnvironment.get_Properties("FontsAndColors", "TextEditor");
    Property prop = propertiesList.Item("FontSize");
    int fontSize = (System.Int16)prop.Value;