'determining the code editor font choice from a VSIX addin custom tool window
I’m creating a VSIX addin which adds a custom tool window for VS 2022. The tool window is intended to be docked alongside the code editor.
I’d like the tool window font to match the font set for the code editor by the user in VS settings.
How can I determine the currently set code editor font in VS 2022? And then how can I setup my custom tool window to just use that?
Solution 1:[1]
Found this which helped. In the tool window Initialize, got the DTE ref with the below.
var dte = GetService(typeof(SDTE)) as DTE;
Then in my view model, I update the current font face and size using the below. These are data bound to the main control in the window. The conversion gets it from points to WPF pixels.
var plist = _dte.get_Properties("FontsAndColors", "TextEditor");
var prop = plist.Item("FontSize") as Property;
if (prop != null)
{
var szPoints = (System.Int16)prop.Value;
// need to convert from points to WPF pixels
FontSize = (int)(((double)szPoints * (96.0 / 72.0)) + 0.5);
}
prop = plist.Item("FontFamily") as Property;
if (prop != null)
{
FontFamily = (string)prop.Value;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nerdtron |
