I'm trying to create an instance of System.Drawing.Font using the SYSTEM_FONT stock object using System.Drawing.Font.FromHfont(IntPtr hfont)
, like so:
static Font GetStockFont(StockObjects index)
{
Font returnFont = Font.FromHfont(GetStockObject(index));
return returnFont;
}
[DllImport("gdi32.dll")]
static extern IntPtr GetStockObject(StockObjects fnObject);
enum StockObjects
{
WHITE_BRUSH = 0,
LTGRAY_BRUSH = 1,
GRAY_BRUSH = 2,
DKGRAY_BRUSH = 3,
BLACK_BRUSH = 4,
NULL_BRUSH = 5,
HOLLOW_BRUSH = NULL_BRUSH,
WHITE_PEN = 6,
BLACK_PEN = 7,
NULL_PEN = 8,
OEM_FIXED_FONT = 10,
ANSI_FIXED_FONT = 11,
ANSI_VAR_FONT = 12,
SYSTEM_FONT = 13,
DEVICE_DEFAULT_FONT = 14,
DEFAULT_PALETTE = 15,
SYSTEM_FIXED_FONT = 16,
DEFAULT_GUI_FONT = 17,
DC_BRUSH = 18,
DC_PEN = 19
}
But when I do I'm getting the following System.ArgumentException
exception, is there something I'm missing? I was under the impression that GetStockObject in this case would return a proper HFont:
Only TrueType fonts are supported. This is not a TrueType font.