Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default fonts 6

Status
Not open for further replies.

SkennyR

Programmer
Mar 7, 2004
157
US
Hello all..
I am writing a small program that will allow users to pick from a few fonts in a menu.
I was wondering if there is anyway to tell what fonts the user has on his(hers) computer.
If I, for example, give comic sans ms as a choice, but the user's computer doesnt have that font, what will happen if the user chooses it in my program?
It would be nice if i could get the available fonts, and have the program build the menu list based on that, or maybe disable the menu choices for the ones that the user doesnt have.
If there is an easier way to do this, I would appreciate the advice.
Thanks..
 
Hi there,

I think a suitable solution would be to add the Microsoft Commondialog control to your project. This will give the end user an interface for choosing a font of which they are likely already familiar. Call it as follows:

Code:
With CommonDialog1
    .Flags = cdlCFBoth
    .ShowFont
End With

Commondialog1.fontname will return the chosen font. There are other properties available for bold, underline, italics, etc...

I hope this helps.

Best regards,
Harold

***You can't change your past, but you can change your future***
 
[tt][blue]
Dim i As Long

For i = 1 To Screen.FontCount
Debug.Print Screen.Fonts(i)
Next
[/blue][/tt]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
George,

That's a cool trick. :) I don't work with fonts a bunch, and that's a new one to me. Have a star for teaching me a new trick. :)

Best regards,
Harold

***You can't change your past, but you can change your future***
 
Thanks to both you guys, but I have another question.
Harold, I like using the common dialog box, and George, that is a neat piece of code, but there are several fonts listed in the common dialog box that are not listed in the code George posted.
Why is this?
 
Never mind, I didnt have the test form big enough to display all by using the code George posted.
BTW, I dont see anything when I use Debug.Print.Screen, but when I just use Print, it prints to the form.
Thanks to both you guys for your help!
 
One more question: How do I transfer the items selected in the common dialog box to the font in a label?
 
Great tip! I just know that will come in handy some time.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Hi SkennyR,

Use this to assign the font to your label:

Code:
Label1.Font = CommonDialog1.FontName

I hope it helps.

Best regards,
Harold

***You can't change your past, but you can change your future***
 
SkennyR said:
BTW, I dont see anything when I use Debug.Print.Screen

In vb, there is an immediate window. When you run the code in the IDE (by pressing F5), you should be able to see the results of the Debug.Print. If your immediate window is not visible, then pressing CTRL-G will cause it to appear. The immediate window is a valuable tool for debugging an application, I encourage you to spend a couple minutes learning how to use it.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thanks George, It is simply amazing how much I dont know.
I will use the immediate window from now on. Very handy tool.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top