Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Outlines an issue with VisualStyleRenderer.GetFont / GetThemeFont whereby an actual value is never returned
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();
}
}
}
@mika76

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.