472,126 Members | 1,452 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,126 software developers and data experts.

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 5697
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
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.