469,658 Members | 1,778 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,658 developers. It's quick & easy.

Fixed-width font issues

I wanted to display text in a label on a Windows form in a fixed-width font.
In C++ Windows API programming I’ve always used:

GetStockObject(SYSTEM_FIXED_FONT).

Using the following C# code to do the same throws an exception:
[System.Runtime.InteropServices.DllImportAttribute( "gdi32.dll")]
private static extern IntPtr GetStockObject(int fnObject);
private static Font GetSystemFont()
{
// Get a handle for a GDI font.
IntPtr hFont = GetStockObject(16); // #define SYSTEM_FIXED_FONT 16
// Create a Font object from hFont.
return Font.FromHfont(hFont);
}

Unhandled Exception: System.ArgumentException: Only TrueType fonts are
supported, and this is not a TrueType font.

Is there a way I can do what I want to do?

Nov 16 '05 #1
2 5579
Unless you really like doing it the hard way try:
FontFamily.GenericMonoSpace

Cheers

Doug Forster

"dlgproc" <dl*****@discussions.microsoft.com> wrote in message
news:CC**********************************@microsof t.com...
I wanted to display text in a label on a Windows form in a fixed-width
font.
In C++ Windows API programming I've always used:

GetStockObject(SYSTEM_FIXED_FONT).

Using the following C# code to do the same throws an exception:
[System.Runtime.InteropServices.DllImportAttribute( "gdi32.dll")]
private static extern IntPtr GetStockObject(int fnObject);
private static Font GetSystemFont()
{
// Get a handle for a GDI font.
IntPtr hFont = GetStockObject(16); // #define SYSTEM_FIXED_FONT 16
// Create a Font object from hFont.
return Font.FromHfont(hFont);
}

Unhandled Exception: System.ArgumentException: Only TrueType fonts are
supported, and this is not a TrueType font.

Is there a way I can do what I want to do?

Nov 16 '05 #2
Thanks

"Doug Forster" wrote:
Unless you really like doing it the hard way try:
FontFamily.GenericMonoSpace

Cheers

Doug Forster

"dlgproc" <dl*****@discussions.microsoft.com> wrote in message
news:CC**********************************@microsof t.com...
I wanted to display text in a label on a Windows form in a fixed-width
font.
In C++ Windows API programming I've always used:

GetStockObject(SYSTEM_FIXED_FONT).

Using the following C# code to do the same throws an exception:
[System.Runtime.InteropServices.DllImportAttribute( "gdi32.dll")]
private static extern IntPtr GetStockObject(int fnObject);
private static Font GetSystemFont()
{
// Get a handle for a GDI font.
IntPtr hFont = GetStockObject(16); // #define SYSTEM_FIXED_FONT 16
// Create a Font object from hFont.
return Font.FromHfont(hFont);
}

Unhandled Exception: System.ArgumentException: Only TrueType fonts are
supported, and this is not a TrueType font.

Is there a way I can do what I want to do?


Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

26 posts views Thread by Adrian Parker | last post: by
9 posts views Thread by Paul Trautwein | last post: by
6 posts views Thread by Mason A. Clark | last post: by
2 posts views Thread by hq105862 | last post: by
2 posts views Thread by Jonathan Carmichael | last post: by
9 posts views Thread by pout | last post: by
1 post views Thread by O.B. | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.