Created
September 15, 2011 12:34
-
-
Save shellscape/1219126 to your computer and use it in GitHub Desktop.
Outlines an issue with VisualStyleRenderer.GetFont / GetThemeFont whereby an actual value is never returned
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Drawing; | |
using System.Linq; | |
using System.Reflection; | |
using System.Text; | |
using System.Windows.Forms; | |
using System.Windows.Forms.VisualStyles; | |
namespace VisualStyleGetFontTest { | |
class Program { | |
static void Main(string[] args) { | |
//VisualStyleElement.Button.CheckBox.CheckedNormal | |
Type vsElementType = typeof(VisualStyleElement); | |
Type[] elementTypes = vsElementType.GetNestedTypes(); | |
// enum the groups | |
foreach (Type elementType in elementTypes) { | |
// enum the elements | |
foreach (Type subType in elementType.GetNestedTypes()) { | |
// enum the parts | |
foreach (PropertyInfo prop in subType.GetProperties(BindingFlags.Public | BindingFlags.Static)) { | |
VisualStyleElement element = prop.GetValue(null, null) as VisualStyleElement; | |
Font font; | |
try { | |
VisualStyleRenderer renderer = new VisualStyleRenderer(element); | |
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) { | |
font = renderer.GetFont(g, FontProperty.GlyphFont); | |
} | |
Console.WriteLine(elementType.Name + "." + subType.Name + "." + prop.Name + " - font: " + (font == null ? "null" : font.ToString())); | |
} | |
catch (ArgumentException) { | |
Console.WriteLine(elementType.Name + "." + subType.Name + "." + prop.Name + " - font: ArgumentException"); | |
} | |
} | |
} | |
} | |
Console.Read(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting, have you reported this to Microsoft? I ask because I just opened a bug for VisualStyleRenderer not initializing a renderer for Menu Item. Check https://connect.microsoft.com/VisualStudio/feedback/details/921798/visualstylerenderer-visualstyleelement-menu-item-normal-returns-not-supported-always