Cant use courier font with PrintDocument - need to print labels

M

MichaelL

I'm trying to print labels and need to use the courier font(not
'courier new') so my horizontal and vertical spacing matches up with
the labels. I've tried using other proportional/monospace fonts but
they don't have proper spacing for my labels and I know that 'courier'
would work.When you 'hover' over the printFont variable, it shows
'Microsoft Sans Serif" as the FontFamily even though I've set to
'Courier'. Other fonts do not have this problem but, the labels are
no good with other fonts. The 'for' loop below doesn't include
'courier' as a part of its output and I'm sure that is a clue but I
don't know what to do with that clue. I know that the courier font is
installed on my machine because it's available to outlook, word, and
even Visual Studio's text editor, however, its just not available to
be used by PrintDocument/Font namespace/class. Any help would be
greatly appreciated.

Imports System.Drawing

Dim printFont As System.Drawing.Font
printFont = New System.Drawing.Font("Courier", 8)
Dim oneFontFamily As System.Drawing.FontFamily
For Each oneFontFamily In System.Drawing.FontFamily.Families
Debug.WriteLine(oneFontFamily.Name)
Next
 
K

Kerry Moorman

MichaelL,

The documentation says:

"Windows Forms applications support TrueType fonts and have limited support
for OpenType fonts. If you attempt to use a font that is not supported, or
the font is not installed on the machine running the application, Microsoft
Sans Serif will be substituted."

If you look at the list of fonts in Word, for example, TrueType fonts have a
TT symbol to the left of the font name. I wonder if the Courier font that is
available to Word on your system is a TrueType font?

Kerry Moorman
 
H

Herfried K. Wagner [MVP]

MichaelL said:
Dim printFont As System.Drawing.Font
printFont = New System.Drawing.Font("Courier", 8)
Dim oneFontFamily As System.Drawing.FontFamily
For Each oneFontFamily In System.Drawing.FontFamily.Families
Debug.WriteLine(oneFontFamily.Name)
Next

The version of the "Courier" font included with Windows is a bitmap font.
'System.Drawing' only supports TrueType and OpenType fonts. What you can do
is to use either plain old GDI via p/invoke or to get a version of "Courier"
in a vector font file format .NET supports.
 
J

Just_a_fan

Don't know why Courier New does not come up there. This very code
(copied and pasted) lists Courier New here:

Comix
Commercial-Script
Congo
Congo Condensed
Congo Extended
Congo Thin
Congo Wide
Continuum Bold
Continuum Light
Continuum Medium
Cornered
Cornerstone
Cotillion
Courier New
Crate
Cuckoo
Cupid
Cupid Condensed
Cupid Wide
Curzon
D730-Deco
Danto

Does Courier New appear in other apps? Word?

Mike
 
H

Herfried K. Wagner [MVP]

Don't know why Courier New does not come up there. This very code
(copied and pasted) lists Courier New here:

Comix
Commercial-Script
Congo
Congo Condensed
Congo Extended
Congo Thin
Congo Wide
Continuum Bold
Continuum Light
Continuum Medium
Cornered
Cornerstone
Cotillion
Courier New
Crate
Cuckoo
Cupid
Cupid Condensed
Cupid Wide
Curzon
D730-Deco
Danto

Does Courier New appear in other apps? Word?


Re-read the OP's post. He attempts to use the Courier font, not Courier
New. As Courier is a bitmap font it cannot be used together with
'System.Drawing'.
 
J

Just_a_fan

Actually, he did mention Courier New at one point. Maybe it had the
"not" and I missed it. Yes, trying to use Courier would fail and fails
here. Sorry.

Why not use Courier New?

Mike
 
H

Harald Hoyer

How can I get a version of "Courier"
in a vector font file format .NET supports?
 
H

Herfried K. Wagner [MVP]

Harald Hoyer said:
How can I get a version of "Courier"
in a vector font file format .NET supports?

I assume that some font vendors license this or very similar fonts in vector
format.
 
H

Harald Hoyer

Actually I searched for things like this. Without success. Probably you
know any vendor that provides this?
What about the other option? (using old GDI) Are there examples
available? (I prefer C#) Is it probably possible to provide a "new" font
type, where the pixel fonds can be wrapped to?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top