473,661 Members | 2,457 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 5827
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
9671
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 the exception of strTotal). The left most positions of the string object are being padded with one...
9
17704
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 the code using the CSS Validator on the W3 site - and it said it's okay.
6
5402
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 everything, but I've seen numerous pages
2
5004
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
4212
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
4184
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
11170
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 clicked on the FIXED row and not on row 1 (since they both produce row = 1 and I cannot tell them apart...
1
10415
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
9414
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 initialize the form data within the project. I am running into problems with statements like the...
15
2704
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 internet connections with Dynamic IP (which means that they change IP addresses, as given by the ISP...
0
8428
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8754
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8542
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2760
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
2
1984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1740
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.