Solved

How to enumerate font sizes for a font

Posted on 2002-07-15
7
319 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel VBA combine two working workbooks 8 54
Visual Studio search word table and return Cell index 8 61
How to Add / Edit Windows Menu 4 60
Automatic Email Reminder 4 37
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…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

773 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