Solved

How to enumerate font sizes for a font

Posted on 2002-07-15
7
322 Views
Last Modified: 2013-12-02
Hello:

In common dialog controls or microsoft word, when we select a font, it lists only selected font sizes. The list varies on font selection. I have a similar need. I need to enumerate font sizes for a given font. In my application, if user types in a font size which is not valid one, vb rich text box or list view will truncate it to the nearest valid number. When user looks at it, he thinks it does not work. If I could limit the choices to the user, then it will be ok.

Is there a way to enumerate the font sizes ?

thanks

0
Comment
Question by:sgarg
7 Comments
 
LVL 22

Expert Comment

by:rspahitz
ID: 7155261
If you are using true-type fonts, there are not "font sizes" even though Office limits the selection.  True type fonts, by design, are fully-scalable to any font size, including fractional sizes (like 8.5)

When you see a list with a discrete set of font sizes on a true-type font, I think it represents "common, suggested" font sizes.

When you see font sizes on non-scalable fonts (such as .FON extensions), this means that they are bitmap fonts and any font size that is not in the specified list is not support (but will appear using some pixelated version.)  However, I am not familiar with the file-format for these so I'm not sure how to determine the font size selection available.
0
 

Author Comment

by:sgarg
ID: 7155295
I use MS Sans Serif and user can type 9 for the font size but rich text box when assigned the size 9, will truncate it down to 8.25.

0
 
LVL 20

Accepted Solution

by:
hes earned 50 total points
ID: 7155317
Could you use something like this

Private Sub Command1_Click()
Dim I As Integer
Dim OldFontSize As Integer
Dim result As Boolean

OldFontSize = RichTextBox1.Font.Size
For I = 1 To 50
  result = SetFontSize(RichTextBox1, I)
  If result Then
  List1.AddItem I
  End If
Next
RichTextBox1.Font.Size = OldFontSize
End Sub

Function SetFontSize(obj As Object, FontSize As Integer) As Boolean
    On Error Resume Next
    obj.Font.Size = FontSize
    SetFontSize = (obj.Font.Size = FontSize)
End Function
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 49

Expert Comment

by:DanRollins
ID: 8012411
Hi sgarg,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Split points between: rspahitz and hes

sgarg, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 8012507
Correction, to make this a worthwhile PAQ:

The font sizes in many Windows products seem to increment in 3/4-point sizes, so hes' code should be modified as follows:

...
Dim I As Single' yeah, I know it's strange, but easier than modifying the entire code
...
For I = 1 To 50 step .75
...

--
Any font that cannot be displayed exactly will be rounded up or down to the nearest 3/4-point.

I find it odd that 9 rounds down since it's on a 3/4-point interval.

Also note that if you omit the 3/4-point step, 7 will round down to 6.75 and 8 will round up to 8.25, and 7.5 will never be included.

 
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 8012521
After further review, I see that the routine is seeking integer font sizes, so I guess you should increment by .25 to catch them all:

...
For I = 1 To 50 step .25
...

0
 

Expert Comment

by:SpideyMod
ID: 8096098
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange

rspahitz points for you at:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20543670.html
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question