Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to enumerate font sizes for a font

Posted on 2002-07-15
7
Medium Priority
?
326 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

721 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