-
Ok spent the weekend searching through manuals etc to solve the following problem, and am out of ideas.
I have a requirement to load a combo box with the available fonts on the end users P.C? Just displaying the standard windows font selection screen is not a solution :(
Further once l have the fonts, and the user selects one, it should then be the default font for another form, (no need to show me how to do the form2.textbox1.font = stuff), therefore l need to be aqble to do something like
form2.textbox1.font = form1.combobox1.item(...index)
Any ideas would be greatfully recieved. :)
Thanks in advance
-
If the only thing you want to set is the font (ie the style and not bold/italics/size etc) then use the FontName attribute
form2.textbox.FontName = form1.combobox.item(form1.combobox.listindex)
As for retrieving the list of registered fonts there must be something either in the registry or an API that would do that for you...
-
Here's one way...
This won't be simple if you aren't familiar with using API calls. There is surely an easier way, but I don't have VB on this computer.
Go to this site to learn about the EnumFontFamilies API. You can use this to return all the fonts available to your program. You have to use a couple of user-defined TYPEs (ENUMLOGFONT, and LOGFONT) to hold the name information, and you have to create a callback function to store the name info about each font returned from the API function.
If I had VB here, I'd try to give an example, but I don't. If you read through these sites you should be able to get enough info to do the job. In the first example (at the first hyperlink above) you would pass Clng(0) as the argument for lpszFamily.
Hopefully someone else will post an easier way, otherwise I will try to come back tomorrow to give you an example.
-
Thanks Gen-X
Yeap just need to be able to display available fonts in a combo box and then select one, and use it in another form
-
The easy way
I am at home now, and have VB here. I found this in the VB help files.
Here's the easy way to do it. There is a font collection associated with both the printer and the screen. You just loop through this collection and add the fonts to the list box.
To list the fonts associated with the screen, do the following:
- Start a new project
- Drop a ListBox and a CommandButton on the form (keep the default names)
- Copy the code below and paste it into the form's code window
- Run the project and click the command button
Code:
Option Explicit
Private Sub Command1_Click()
Dim lCounter As Long
For lCounter = 0 To Screen.FontCount - 1
List1.AddItem Screen.Fonts(lCounter)
Next lCounter
End Sub
To list the fonts associated with the printer, just substitute "Printer" for "Screen" in the above code.
Hope you didn't spend your WHOLE weekend searching...I found this in less than 2 minutes in the VB help files under "FontCount property".
-
P.S.
If you don't have MSDN installed with VB, then this may not have shown up in your help.
If that's the case, you can go to MSDN Online to get the lastest help there. Go here for the FontProperty description.
~seaweed
-
Thanks seaweed,
And no l don't have access to MSDN. Our email P.Cs are separate from out development machines, with company policy dis-allowing the transfer of files between them. This was after a hacker cracked our fire-wall, (FYI have to guard against both TCP-IP and FTP), and a couple of trojans wrecked a major project. :(
Anyway the code looks great, will attempt later today, currently trying to get top form to do what l want with it, (P.C pre-printed stationary replacement for a Universe system). :)