Winforms: Add support for TMT_FONT

Created on 24 May 2020  路  6Comments  路  Source: dotnet/winforms

To make my app look more like native Windows components, while still supporting High Contrast themes, I use VisualStyleRenderer to draw "instruction text" (like the TaskDialog uses). In the default theme, this is 12-point Segoe UI, foreground color #003399. To do this, I use the class TEXTSTYLE, part 1, and state 0 (these values come from vsstyle.h in the Windows SDK).

However, when I attempt this, VisualStyleRenderer.GetFont(FontProperty.GlyphFont) returns null. Investigation using a tool that dumps aero.msstyles reveals that the above class/part/state combination defines TMT_FONT, but not TMT_GLYPHFONT, which is the only valid FontProperty in Windows Forms. Therefore, I must manually P/Invoke into uxtheme.dll every time I want to accomplish this task. I wish to avoid having to do this.

Proposed API is as follows:

 enum FontProperty {
+    TextFont = (int)Interop.TMT.FONT,
     GlyphFont = (int)Interop.TMT.GLYPHFONT
 }

I would also need to update the VisualStyleRenderer class to accept this FontProperty value. This feature does not need VS designer support, should not impact accessibility, and does not need to be localized. Thanks!

api-suggestion theming

All 6 comments

using a tool that dumps aero.msstyles

Out of curiosity, what tool are you using?

Noice!

Providing a better theming experience is on our future roadmap, so fixes and enhancements in this area are quite welcome.

Good idea. I was just looking at the docs and it seems like there are others that we could (should)? be supporting:
From https://docs.microsoft.com/en-us/windows/win32/controls/property-typedefs
ID | Notes
-- | --
TMT_BODYFONT | 聽
TMT_CAPTIONFONT | 聽
TMT_GLYPHFONT | The font that the glyph associated with this part will be drawn with, if font-based glyphs are used.
TMT_HEADING1FONT | 聽
TMT_HEADING2FONT | 聽
TMT_ICONTITLEFONT | 聽
TMT_MENUFONT | 聽
TMT_MSGBOXFONT | 聽
TMT_SMALLCAPTIONFONT | 聽
TMT_STATUSFONT

Note I may be wrong here

@hughbe I would like to disagree. Most of the other IDs you listed correspond to fonts that can already be retrieved using the SystemFonts class. The rest (ICONTITLEFONT, HEADING1FONT, HEADING2FONT) I have never seen used, even when using my msstyles-dumping tool.

Alrighty thats fine then :)

Was this page helpful?
0 / 5 - 0 ratings