473,583 Members | 3,242 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_FO NT).

Using the following C# code to do the same throws an exception:
[System.Runtime. InteropServices .DllImportAttri bute("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_FO NT 16
// Create a Font object from hFont.
return Font.FromHfont( hFont);
}

Unhandled Exception: System.Argument Exception: 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 5821
Unless you really like doing it the hard way try:
FontFamily.Gene ricMonoSpace

Cheers

Doug Forster

"dlgproc" <dl*****@discus sions.microsoft .com> wrote in message
news:CC******** *************** ***********@mic rosoft.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_FO NT).

Using the following C# code to do the same throws an exception:
[System.Runtime. InteropServices .DllImportAttri bute("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_FO NT 16
// Create a Font object from hFont.
return Font.FromHfont( hFont);
}

Unhandled Exception: System.Argument Exception: 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.Gene ricMonoSpace

Cheers

Doug Forster

"dlgproc" <dl*****@discus sions.microsoft .com> wrote in message
news:CC******** *************** ***********@mic rosoft.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_FO NT).

Using the following C# code to do the same throws an exception:
[System.Runtime. InteropServices .DllImportAttri bute("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_FO NT 16
// Create a Font object from hFont.
return Font.FromHfont( hFont);
}

Unhandled Exception: System.Argument Exception: 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
9663
by: Adrian Parker | last post by:
I'm using the code below in my project. When I print all of these fixed length string variables, one per line, they strings in questions do not properly pad with 0s. strQuantity prints as " 4". Six spaces than the value of intQuantity. This is correct. But all the others end up being string objects of only 6 characters long (with...
9
17703
by: Paul Trautwein | last post by:
I'm trying to get an image to float in a window despite scrolling. I've gotten it to work on my Mac using IE 5.2, Netscape, and Safari, but it goes wonky when I test it on a PC. (testing with IE only at the moment.) Positioning is wrong, and it doesn't float at all. Here's a test page: http://www.bdiusa.com/mirrors/test.html I've tested...
6
5398
by: Mason A. Clark | last post by:
Masters: On two or three-column layouts, one column often has a list of links. Scrolling the page hides them. I'm aware there's supposed to be the ability to fix the column (frame-like). I have some bits of such code but haven't yet made it work well. Question: Why have I never seen an example on the web? Not that I've seen...
2
4999
by: hq105862 | last post by:
Hi, Is it possible to simulate frames behaviour with CSS? Currently, I've used CSS to create the visual look of my old framed site. For this I've used styles that place the images at absolute positions. Then I thought, if I fixed the image positions, the images will stay put and the 'body' will scroll up, like in frames.
2
4210
by: Jonathan Carmichael | last post by:
I'm trying to create a fixed, no-repeat, centered background image using an external css. Everything works great until I add background-attachment: fixed then it just doesn't show the image at all. I've tried it using the "all in one" {background: url(SGsmall.jpg) no-repeat center fixed}
9
4177
by: pout | last post by:
What are the purposes of fixed-point? When should it be used? I read: #define Int2Fixed(x) (((long)(short)x) << 16) and the fixed-point in 16.16 format. Does the 16 in the MACRO refer to integer or decimal part? For example, if in 8.24, should the macro be: #define Int2Fixed(x) (((long)(short)x) << 24)?
4
11167
by: Otie | last post by:
Hello, I am using the MSFlexGrd Control in VB5. I have 1 fixed row and one fixed column. I am trying to do a sort when the user clicks a column in the FIXED ROW. But when I capture the row number in the click event I get row = 1 if I click on the FIXED row OR the actual row 1. How can I get the grid control to tell me when the user has...
1
10408
by: O.B. | last post by:
In the example below, I'm trying to convert a fixed byte array to a string. I get an error about needing to use "fixed" but I have no clue where to apply it. Help? using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices;
1
9407
by: Rick Knospler | last post by:
I am trying to convert a vb6 project to vb.net. The conversion worked for the most part except for the fixed length strings and fixed length string arrays. Bascially the vb6 programmer stored all form data in a fixed length structure that is written direct to disk. I need to load the existing files, into a fixed length structure to...
15
2696
by: ingejg | last post by:
I am starting to study internet synchronization, and my head is still spinning since internet is not my forte, however my boss is breathing down my neck at the moment. Our company has only one server with fixed IP address provided by our ISP, while the other sites (which I wish in the future hold the replicas databases) have only standard...
0
7893
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7821
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8172
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8317
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6574
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3839
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2326
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1422
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1151
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.