FontDialog Only Allows Integrals?

G

Guest

I've noticed that the FontDialog only allows positive integers as input when
you show the dialog. Is there some reason for this? The font that it
returns allows singles and I can't really find anywhere that explains why
this might be. We're writing our own FontDialog (due to some other
limitations), and we're trying to find out if there is a practical reason for
this or if we should allow any positive decimal number.

Thanks.
 
B

Bob Powell [MVP]

I assume you're talking about the font height...

The font dialog always creates a font with a point size. This is to a
resolution of 1/72 of an inch so floats in here don't make a lot of sense.

The Font is more or less read-only once created and will return a height in
a floating point number so that the different units might be accommodated.

When you request a font, you may get back a different size to that requested
depending on how the font grid-fitting is calculated. For example a
"standard" 8 point font will probably declare a point size of 8.25 points.
On a screen resolution of 96 DPI this corresponds to exactly 11 pixels
whereas 8 points exacly would be 10.666r pixels. These round to the nearest
pixel.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
G

Guest

Dim fd As New FontDialog
fd.ShowDialog()
Console.WriteLine(fd.Font.SizeInPoints)

If I choose a the font size to be 10 here, the output is 9.75. If I choose
the font size to be 11 here, the output is 11.25. 8 gets 8.25 and 9 gets 9.
So I see what you are saying there, sort of.

What initially brought my question up is when you actually have that font
dialog open, you are forbidden from inputting 9.75, it forces you to put a
positive integer in. Which seems weird, considering that all the Font.Size
methods return Singles.

I'm using scaled fonts through Graphics, and I have not had a problem having
all sorts of font sizes (8.198598 as a point size works beautifully); I'm not
limited to what the FontDialog is rounding me to.

So I guess my main problem is still that the FontDialog inexplicably
prevents my users from using singles. I'm confused as to, if I want the
Dialog to return to me a Font with height 10 or 10.5, why it can't actually
do that. It seems odd that it is limiting itself to one sort of resolution.

Perhaps I'm not understanding what the Size box is intended to be when you
open a FontDialog.

Thanks,
Mike
 
B

Bruce Wood

Bob said:
The font dialog always creates a font with a point size. This is to a
resolution of 1/72 of an inch so floats in here don't make a lot of sense.

I disagree. I don't have a lot of experience using the dialog, but in
MS Word, for example, I do occasionally ask for a font of 8.5 points,
for example, and it is noticeably different from 8 points and from 9
points.

When you get down to the smaller font sizes, a half a point (or even
less) makes a noticeable difference.

Given that other products (MS Word, Crystal Reports designer) allow one
to specify font height in fractions of points, it seems odd that .NET's
standard dialog doesn't.
 

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

Top